Overview¶
DataCards are used for storing, versioning, and tracking data. All DataCards require a DataInterface
and optional metadata. See DataInterface for more information
Creating a Card¶
# Data
from sklearn.datasets import load_linnerud
from sklearn.model_selection import train_test_split
import numpy as np
# Opsml
from opsml import CardInfo, DataCard, CardRegistry, DataSplit, PandasData
card_info = CardInfo(name="linnerrud", repository="opsml", contact="user@email.com")
data, target = load_linnerud(return_X_y=True, as_frame=True)
data["Pulse"] = target.Pulse
# Split indices
indices = np.arange(data.shape[0])
# usual train-val split
train_idx, test_idx = train_test_split(indices, test_size=0.2, train_size=None)
data_interface = PandasData(
data=data,
dependent_vars=["Pulse"],
# define splits
data_splits=[
DataSplit(label="train", indices=train_idx),
DataSplit(label="test", indices=test_idx),
],
)
data_card = DataCard(info=card_info, interface=data_interface)
# splits look good
splits = data_card.split_data()
print(splits["train"].X.head())
"""
Chins Situps Jumps
0 5.0 162.0 60.0
1 2.0 110.0 60.0
2 12.0 101.0 101.0
3 12.0 105.0 37.0
4 13.0 155.0 58.0
"""
data_registry = CardRegistry(registry_name="data")
data_registry.register_card(card=data_card)
print(data_card.version)
# > 1.0.0
DataCard Args¶
name
:str
- Name for the data (Required)
repository
:str
- repository data belongs to (Required)
contact
:str
- Email to associate with data (Required)
interface
:DataInterface
- DataInterface used to interact with data. See DataInterface for more information
metadata
:DataCardMetadata
- Optional DataCardMetadata used to store metadata about data. See DataCardMetadata for more information. If not provided, a default object is created. When registering a card, the metadata is updated with the latest information.
Docs¶
opsml.DataCard
¶
Bases: ArtifactCard
Create a DataCard from your data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
interface |
Instance of |
required | |
name |
What to name the data |
required | |
repository |
Repository that this data is associated with |
required | |
contact |
Contact to associate with data card |
required | |
info |
Name, repository, and contact are required arguments for all cards. They can be provided
directly or through a |
required | |
version |
DataCard version |
required | |
uid |
Unique id assigned to the DataCard |
required |
Returns:
Type | Description |
---|---|
DataCard |
Source code in opsml/cards/data.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
|
card_type: str
property
¶
create_data_profile(bin_size=20, compute_correlations=False)
¶
Create data profile for the current data card
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bin_size |
int
|
Number of bins for histograms. Default is 20 |
20
|
compute_correlations |
bool
|
Whether to compute correlations or not. Default is False |
False
|
Source code in opsml/cards/data.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
split_data()
¶
Splits data interface according to data split logic
Source code in opsml/cards/data.py
147 148 149 150 151 152 153 154 |
|
load_data(**kwargs)
¶
Load data to interface
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kwargs |
Union[str, int]
|
Keyword arguments to pass to the data loader |
{}
|
split |
Split to use for data. If not provided, then all data will be loaded.
Only used for subclasses of |
required | |
batch_size |
What batch size to use when loading data. Only used for subclasses of |
required | |
chunk_size |
How many files per batch to use when writing arrow back to local file. Defaults to 1000. Example:
|
required |
Source code in opsml/cards/data.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
|