示例#1
0
 def test_init_fit_predict(self):
     import sklearn.datasets
     import sklearn.svm
     svm = sklearn.svm.SVR(kernel='linear')
     rfe = RFE(estimator=svm, n_features_to_select=2)
     lr = LogisticRegression()
     trainable = rfe >> lr
     data = sklearn.datasets.load_iris()
     X, y = data.data, data.target
     trained = trainable.fit(X, y)
     predicted = trained.predict(X)
示例#2
0
    def test_hyperparam_estimator(self):
        lr = LogisticRegression()
        linear_reg = LinearRegression()
        ada = AdaBoostRegressor(base_estimator=lr)

        replaced_ada = ada.replace(lr, linear_reg)
        expected_ada = AdaBoostRegressor(base_estimator=linear_reg)
        self.assertEqual(replaced_ada.to_json(), expected_ada.to_json())

        replaced_ada = ada.replace(LogisticRegression, linear_reg)
        expected_ada = AdaBoostRegressor(base_estimator=linear_reg)
        self.assertEqual(replaced_ada.to_json(), expected_ada.to_json())

        ada_pipeline = PCA >> SimpleImputer >> ada
        replaced_pipeline = ada_pipeline.replace(lr, linear_reg)
        expected_pipeline = (
            PCA >> SimpleImputer >> AdaBoostRegressor(base_estimator=linear_reg)
        )
        self.assertEqual(replaced_pipeline.to_json(), expected_pipeline.to_json())

        ada_choice = PCA | ada
        replaced_choice = ada_choice.replace(lr, linear_reg)
        expected_choice = PCA | AdaBoostRegressor(base_estimator=linear_reg)
        self.assertEqual(replaced_choice.to_json(), expected_choice.to_json())

        rfe = RFE(estimator=lr)
        replaced_rfe = rfe.replace(lr, linear_reg)
        expected_rfe = RFE(estimator=linear_reg)
        self.assertEqual(replaced_rfe.to_json(), expected_rfe.to_json())
    def test_attrib(self):
        import sklearn.datasets

        from lale.lib.sklearn import RFE, LogisticRegression

        svm = lale.lib.sklearn.SVR(kernel="linear")
        rfe = RFE(estimator=svm, n_features_to_select=2)
        lr = LogisticRegression()
        trainable = rfe >> lr
        data = sklearn.datasets.load_iris()
        X, y = data.data, data.target
        trained = trainable.fit(X, y)
        _ = trained.predict(X)
        from lale.lib.lale import Hyperopt

        opt = Hyperopt(estimator=trainable, max_evals=2, verbose=True)
        opt.fit(X, y)
 def test_not_operator(self):
     with EnableSchemaValidation():
         with self.assertRaises(jsonschema.ValidationError):
             _ = RFE(estimator='"not an operator"', n_features_to_select=2)