Dataset
Dataset
Bases: dict
A class representing a dataset.
This class extends the built-in dict
class and provides additional functionality for working with datasets.
Attributes:
Name | Type | Description |
---|---|---|
data_splitter |
An optional data splitter object used to split the data into train and test sets. |
|
target_column |
The name of the target column in the data. |
|
name |
The name of the dataset. |
|
_is_data_splitted |
A flag indicating whether the data has been split. |
|
data |
The input data for the dataset. |
|
_X |
The feature matrix X. |
|
_y |
The target variable array. |
|
splits |
A dictionary containing the splits of the dataset. |
Methods:
Name | Description |
---|---|
X |
Returns the feature matrix X. |
y |
Returns the target variable array. |
columns |
Returns the list of column names. |
shape |
Returns the shape of the feature matrix X. |
_split_data |
Splits the data into train and test sets. |
_run_checks |
Runs checks on the splits to ensure data integrity. |
load_split |
Loads a specific split of the dataset. |
load_train_test |
Loads the training and testing data splits from the dataset. |
create_from_pipeline |
Creates a dataset from a data loading function and optional data pipeline. |
create_from_splits |
Creates a dataset from splits. |
Source code in model_forge/data/dataset.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 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 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
|
X: pd.DataFrame
property
Returns the feature matrix X.
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: The feature matrix X. |
columns
property
Returns a list of column names in the dataset.
Returns:
Name | Type | Description |
---|---|---|
list |
A list of column names. |
shape
property
Returns the shape of the dataset.
Returns:
Name | Type | Description |
---|---|---|
tuple |
A tuple representing the shape of the dataset. |
y: np.array
property
Returns the target variable array.
Returns:
Type | Description |
---|---|
array
|
np.array: The target variable array. |
__getattr__(attr_name)
Retrieves the attribute specified by __name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__name |
str
|
The name of the attribute to retrieve. |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The value of the attribute. |
Raises:
Type | Description |
---|---|
AttributeError
|
If the attribute specified by __name is not found. |
Source code in model_forge/data/dataset.py
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 179 180 181 182 183 184 185 186 187 188 189 |
|
__getitem__(key)
Retrieve an item from the dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
Any
|
The key used to retrieve the item. |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The item corresponding to the given key. |
Source code in model_forge/data/dataset.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
|
__init__(data, data_splitter=None, target_column='y', name='dataset', splits_columns=None)
Initialize a Dataset object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
DataFrame
|
The input data for the dataset. |
required |
data_splitter |
optional
|
An optional data splitter object used to split the data into train and test sets. |
None
|
target_column |
str
|
The name of the target column in the data. |
'y'
|
name |
str
|
The name of the dataset. |
'dataset'
|
Returns:
Type | Description |
---|---|
None
|
None |
Source code in model_forge/data/dataset.py
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 |
|
create_from_pipeline(data_loading_function, data_pipeline=None, data_splitter=None, target_column='y', name='dataset', splits_columns=None)
classmethod
Create a dataset from a data loading function and optional data pipeline.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cls |
The class of the dataset. |
required | |
data_loading_function |
Callable[[], DataFrame]
|
A function that loads the data and returns a pandas DataFrame. |
required |
data_pipeline |
An optional data pipeline to apply to the loaded data. |
None
|
|
data_splitter |
An optional data splitter to split the data into train and test sets. |
None
|
|
target_column |
The name of the target column in the dataset. |
'y'
|
|
name |
str
|
The name of the dataset. |
'dataset'
|
Returns:
Type | Description |
---|---|
An instance of the dataset class. |
Source code in model_forge/data/dataset.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
|
create_from_splits(splits, name='dataset', target_column='y')
classmethod
Create a dataset from splits.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cls |
class
|
The class of the dataset. |
required |
splits |
dict[str, tuple[DataFrame, array]]
|
A dictionary containing the splits of the dataset. Each split is represented as a tuple of a pandas DataFrame (X) and a numpy array (y). |
required |
name |
str
|
The name of the dataset. Defaults to "dataset". |
'dataset'
|
target_column |
str
|
The name of the target column. Defaults to "y". |
'y'
|
Returns:
Name | Type | Description |
---|---|---|
dataset |
cls
|
The created dataset. |
Source code in model_forge/data/dataset.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
|
load_split(split, return_X_y=False, sample_n_rows=None, random_state=36)
Load a specific split of the dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
split |
str
|
The name of the split to load. |
required |
return_X_y |
bool
|
Whether to return X and y separately. Defaults to False. |
False
|
sample_n_rows |
int
|
Number of rows to sample from the split. Defaults to None. |
None
|
random_state |
int
|
Random state for sampling rows. Defaults to 36. |
36
|
Returns:
Type | Description |
---|---|
Union[tuple[DataFrame, array], DataFrame]
|
Union[tuple[pd.DataFrame, np.array], pd.DataFrame]: The loaded split of the dataset. If return_X_y is True, returns a tuple of X and y. If return_X_y is False, returns a DataFrame with X and y as columns. |
Source code in model_forge/data/dataset.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
|