def test_rfr(self): from lale.lib.sklearn import RandomForestRegressor reg = RandomForestRegressor(bootstrap=True, criterion='friedman_mse', max_depth=4, max_features=0.9832410473940374, max_leaf_nodes=None, min_impurity_decrease=0.0, min_impurity_split=None, min_samples_leaf=3, min_samples_split=2, min_weight_fraction_leaf=0.0, n_estimators=29, n_jobs=4, oob_score=False, random_state=33, verbose=0, warm_start=False) reg.fit(self.X_train, self.y_train)
def test_pipeline_AWTTR_1(self): trainable = AutoaiTSPipeline(steps=[( "AutoaiWindowTransformedTargetRegressor", AutoaiWindowTransformedTargetRegressor( regressor=SmallDataWindowTransformer() >> SimpleImputer() >> RandomForestRegressor()), )]) self.doTestPipeline(trainable, self.y, self.y, self.y, self.y)
def test_pipeline_AWWR(self): trainable = AutoaiTSPipeline(steps=[( "AutoaiWindowTransformedTargetRegressor", AutoaiWindowedWrappedRegressor( regressor=SmallDataWindowTransformer() >> SimpleImputer() >> RandomForestRegressor()), )]) self.doTestPipeline(trainable, self.y, self.y, self.y, self.y, optimization=True)
def test_pipeline_AWTTR_2(self): trainable = AutoaiTSPipeline(steps=[( "AutoaiWindowTransformedTargetRegressor", AutoaiWindowTransformedTargetRegressor( regressor=SmallDataWindowTransformer() >> SimpleImputer() >> RandomForestRegressor(), estimator_prediction_type="rowwise", ), )]) self.doTestPipeline(trainable, self.y, self.y, self.y, self.y, optimization=True)
'input_predict': _input_predict_schema, 'output': _output_predict_schema } } HyperoptRegressor = lale.operators.make_operator(HyperoptRegressorImpl, _combined_schemas) if __name__ == '__main__': from lale.lib.lale import ConcatFeatures from lale.lib.sklearn import Nystroem, PCA, RandomForestRegressor from sklearn.metrics import r2_score pca = PCA(n_components=3) nys = Nystroem(n_components=3) concat = ConcatFeatures() rf = RandomForestRegressor() trainable = (pca & nys) >> concat >> rf #trainable = nys >>rf import sklearn.datasets from lale.helpers import cross_val_score diabetes = sklearn.datasets.load_diabetes() X, y = sklearn.utils.shuffle(diabetes.data, diabetes.target, random_state=42) hp_n = HyperoptRegressor(estimator=trainable, max_evals=20) hp_n_trained = hp_n.fit(X, y) predictions = hp_n_trained.predict(X) mse = r2_score(y, [round(pred) for pred in predictions])
def test_max_samples(self): with self.assertRaisesRegex(jsonschema.ValidationError, "argument 'max_samples' was unexpected"): _ = RandomForestRegressor(max_samples=0.01)
def test_ccp_alpha(self): with self.assertRaisesRegex(jsonschema.ValidationError, "argument 'ccp_alpha' was unexpected"): _ = RandomForestRegressor(ccp_alpha=0.01)
def test_n_estimators(self): default = RandomForestRegressor.hyperparam_defaults()["n_estimators"] self.assertEqual(default, 10)
def test_with_defaults(self): trainable = RandomForestRegressor() trained = trainable.fit(self.train_X, self.train_y) _ = trained.predict(self.test_X)