r"""Get data for the given partition. Parameters ---------- model : alphapy.Model The model object describing the data. partition : alphapy.Partition Reference to the dataset. Returns ------- X : pandas.DataFrame The feature set. y : pandas.S
(model, partition)
| 82 | # |
| 83 | |
| 84 | def get_data(model, partition): |
| 85 | r"""Get data for the given partition. |
| 86 | |
| 87 | Parameters |
| 88 | ---------- |
| 89 | model : alphapy.Model |
| 90 | The model object describing the data. |
| 91 | partition : alphapy.Partition |
| 92 | Reference to the dataset. |
| 93 | |
| 94 | Returns |
| 95 | ------- |
| 96 | X : pandas.DataFrame |
| 97 | The feature set. |
| 98 | y : pandas.Series |
| 99 | The array of target values, if available. |
| 100 | |
| 101 | """ |
| 102 | |
| 103 | logger.info("Loading Data") |
| 104 | |
| 105 | # Extract the model data |
| 106 | |
| 107 | directory = model.specs['directory'] |
| 108 | extension = model.specs['extension'] |
| 109 | features = model.specs['features'] |
| 110 | model_type = model.specs['model_type'] |
| 111 | separator = model.specs['separator'] |
| 112 | target = model.specs['target'] |
| 113 | |
| 114 | # Initialize X and y |
| 115 | |
| 116 | X = pd.DataFrame() |
| 117 | y = np.empty([0, 0]) |
| 118 | |
| 119 | # Read in the file |
| 120 | |
| 121 | filename = datasets[partition] |
| 122 | input_dir = SSEP.join([directory, 'input']) |
| 123 | df = read_frame(input_dir, filename, extension, separator) |
| 124 | |
| 125 | # Get features and target |
| 126 | |
| 127 | if not df.empty: |
| 128 | if target in df.columns: |
| 129 | logger.info("Found target %s in data frame", target) |
| 130 | # check if target column has NaN values |
| 131 | nan_count = df[target].isnull().sum() |
| 132 | if nan_count > 0: |
| 133 | logger.info("Found %d records with NaN target values", nan_count) |
| 134 | logger.info("Labels (y) for %s will not be used", partition) |
| 135 | else: |
| 136 | # assign the target column to y |
| 137 | y = df[target] |
| 138 | # encode label only for classification |
| 139 | if model_type == ModelType.classification: |
| 140 | y = LabelEncoder().fit_transform(y) |
| 141 | logger.info("Labels (y) found for %s", partition) |
no test coverage detected