def run(cls, proba, preprocessing, **kwargs): """Function for executing specified test.""" if cls == 'subset': p = kwargs['n_partitions'] else: p = 1 ests = ESTS[(proba, preprocessing)] prep = PREPROCESSING if preprocessing else None data = Data(cls, proba, preprocessing, **kwargs) X, y = data.get_data((LEN, WIDTH), MOD) (F, wf), _ = data.ground_truth(X, y, p) ens = EnsembleTransformer() ens.add(cls, ests, prep, proba=proba, **kwargs) ens.fit(X, y) pred = ens.transform(X) np.testing.assert_array_equal(F, pred)
lc_transform) PROBA = True PROCESSING = True LEN = 12 WIDTH = 2 FOLDS = 3 PARTITIONS = 2 MOD, r = divmod(LEN, FOLDS) assert r == 0 lg = LayerGenerator() data = Data('subset', PROBA, PROCESSING, PARTITIONS, FOLDS) X, y = data.get_data((LEN, WIDTH), MOD) (F, wf), (P, wp) = data.ground_truth(X, y, subsets=PARTITIONS) layer = lg.get_layer('subset', PROBA, PROCESSING, PARTITIONS, FOLDS) lc = lg.get_layer_container('subset', PROBA, PROCESSING, PARTITIONS, FOLDS) layer.indexer.fit(X) cache = Cache(X, y, data) def test_layer_fit(): """[Parallel | Subset | Prep | Proba] test layer fit.""" layer_fit(layer, cache, F, wf) def test_layer_predict():
lc_fit, lc_from_file, lc_from_csv, lc_predict, lc_transform, lc_feature_prop) PROBA = True PROCESSING = False LEN = 6 WIDTH = 2 FOLDS = 3 MOD, r = divmod(LEN, FOLDS) assert r == 0 lg = LayerGenerator() data = Data('blend', PROBA, PROCESSING) X, y = data.get_data((LEN, WIDTH), MOD) (F, wf), (P, wp) = data.ground_truth(X, y) layer = lg.get_layer('blend', PROBA, PROCESSING) lc = lg.get_layer_container('blend', PROBA, PROCESSING) lc_p = lg.get_layer_container('blend', PROBA, PROCESSING, propagate_features=[1]) layer.indexer.fit(X) cache = Cache(X, y, data) def test_layer_fit(): """[Parallel | Blend | No Prep | Proba] test layer fit."""
""" import numpy as np from mlens.metrics import rmse from mlens.base import BlendIndex from mlens.utils.dummy import Data, ESTIMATORS, PREPROCESSING, OLS from mlens.ensemble import BlendEnsemble LEN = 6 WIDTH = 2 MOD = 2 data = Data('blend', False, True) X, y = data.get_data((LEN, WIDTH), MOD) (F, wf), (P, wp) = data.ground_truth(X, y, 1, False) def test_run(): """[Blend] 'fit' and 'predict' runs correctly.""" meta = OLS() meta.fit(F, y[3:]) g = meta.predict(P) ens = BlendEnsemble(test_size=3) ens.add(ESTIMATORS, PREPROCESSING, dtype=np.float64) ens.add(OLS(), meta=True, dtype=np.float64) ens.fit(X, y) pred = ens.predict(X)
raise ValueError def null_func(y, p): """Test for failed aggregation""" return 'not_value' FOLDS = 3 LEN = 6 WIDTH = 2 MOD = 2 data1 = Data('stack', False, True, FOLDS) X1, y1 = data1.get_data((LEN, WIDTH), MOD) (F1, wf1), (P1, wp1) = data1.ground_truth(X1, y1, 1, False) G1 = OLS().fit(F1, y1).predict(P1) data2 = Data('stack', False, False, FOLDS) X2, y2 = data1.get_data((LEN, WIDTH), MOD) (F2, wf2), (P2, wp2) = data2.ground_truth(X2, y2, 1, False) G2 = OLS().fit(F2, y2).predict(P2) ens1 = SuperLearner(folds=FOLDS, scorer=rmse, verbose=100) ens1.add(ESTIMATORS, PREPROCESSING, dtype=np.float64) ens1.add_meta(OLS(), dtype=np.float64) ens1_b = SuperLearner(folds=FOLDS, scorer=in_script_func) ens1_b.add(ESTIMATORS, PREPROCESSING, dtype=np.float64) ens1_b.add_meta(OLS(), dtype=np.float64)