|
4 | 4 | from typing import Tuple
|
5 | 5 |
|
6 | 6 | from pandas_ml_common import pd, np, naive_splitter, random_splitter
|
7 |
| -from pandas_ml_utils import FeaturesAndLabels, Model |
| 7 | +from pandas_ml_utils import FeaturesAndLabels, Model, SubModelFeature |
8 | 8 | from pandas_ml_utils.ml.model.base_model import AutoEncoderModel
|
9 | 9 |
|
10 | 10 |
|
@@ -229,6 +229,38 @@ def test_no_test_data(self):
|
229 | 229 | self.assertEqual(len(fit.training_summary.df), len(df))
|
230 | 230 | self.assertEqual(len(fit.test_summary.df), 0)
|
231 | 231 |
|
| 232 | + def test_stacked_models(self): |
| 233 | + """given some toy classification data""" |
| 234 | + df = pd.DataFrame({ |
| 235 | + "a": [1, 0, 1, 0, 1, 0, 1, 0, ], |
| 236 | + "b": [0, 0, 1, 1, 0, 0, 1, 1, ], |
| 237 | + "c": [1, 0, 0, 1, 1, 0, 0, 1, ] |
| 238 | + }) |
| 239 | + |
| 240 | + """and a model""" |
| 241 | + model = self.provide_classification_model( |
| 242 | + FeaturesAndLabels( |
| 243 | + features=[ |
| 244 | + "a", |
| 245 | + SubModelFeature("b", self.provide_classification_model( |
| 246 | + FeaturesAndLabels(features=["a", "b"], labels=["c"], label_type=int) |
| 247 | + )) |
| 248 | + ], |
| 249 | + labels=["c"], |
| 250 | + label_type=int |
| 251 | + ) |
| 252 | + ) |
| 253 | + |
| 254 | + with self.assertLogs(level='INFO') as cm: |
| 255 | + with df.model() as m: |
| 256 | + m.fit(model) |
| 257 | + |
| 258 | + self.assertIn("INFO:pandas_ml_utils.ml.model.base_model:fitting submodel: b", cm.output[0]) |
| 259 | + self.assertIn( |
| 260 | + "INFO:pandas_ml_utils.ml.model.base_model:fitted submodel", |
| 261 | + [s for s in cm.output if s.startswith("INFO:pandas_ml_utils.ml.model.base_model:fitted")][0] |
| 262 | + ) |
| 263 | + |
232 | 264 |
|
233 | 265 | # Abstract methods
|
234 | 266 | def provide_batch_size_and_epoch(self) -> Tuple[int, int]:
|
|
0 commit comments