Ejemplo n.º 1
0
    def test_shallow_planned_nested_indiv_operator(self):
        from lale.lib.sklearn import BaggingClassifier, DecisionTreeClassifier

        clf = BaggingClassifier(base_estimator=DecisionTreeClassifier())
        params = clf.get_params(deep=False)
        filtered_params = self.remove_lale_params(params)
        assert filtered_params["bootstrap"]
Ejemplo n.º 2
0
    def test_with_hyperopt(self):
        from lale.lib.lale import Hyperopt
        from lale.lib.sklearn import BaggingClassifier

        clf = BaggingClassifier(base_estimator=LogisticRegression())
        trained = clf.auto_configure(self.X_train, self.y_train, Hyperopt, max_evals=1)
        print(trained.to_json())
Ejemplo n.º 3
0
 def test_pipeline_with_hyperopt(self):
     from lale.lib.sklearn import BaggingClassifier
     from lale.lib.lale import Hyperopt
     clf = BaggingClassifier(base_estimator=PCA() >> LogisticRegression())
     trained = clf.auto_configure(self.X_train,
                                  self.y_train,
                                  Hyperopt,
                                  max_evals=1)
Ejemplo n.º 4
0
 def test_bagging_post_estimator_mitigation_base(self):
     model = BaggingClassifier(
         base_estimator=CalibratedEqOddsPostprocessing(
             **self.fairness_info, estimator=DecisionTreeClassifier()
         )
     )
     self._attempt_fit_predict(model)
Ejemplo n.º 5
0
 def test_bagging_in_estimator_mitigation_base_1(self):
     if tensorflow_installed:
         tf.compat.v1.disable_eager_execution()
         model = BaggingClassifier(
             base_estimator=AdversarialDebiasing(**self.fairness_info),
             n_estimators=2,
         )
         self._attempt_fit_predict(model)
Ejemplo n.º 6
0
    def test_deep_planned_nested_indiv_operator(self):
        from lale.lib.sklearn import BaggingClassifier, DecisionTreeClassifier

        dtc = DecisionTreeClassifier()
        clf = BaggingClassifier(base_estimator=dtc)
        params = clf.get_params(deep=True)
        filtered_params = self.remove_lale_params(params)

        # expected = LogisticRegression.get_defaults()
        base = filtered_params["base_estimator"]
        base_params = self.remove_lale_params(base.get_params(deep=True))
        nested_base_params = nest_HPparams("base_estimator", base_params)
        self.assertDictEqual(
            {
                k: v
                for k, v in filtered_params.items()
                if k.startswith("base_estimator__")
                and not k.startswith("base_estimator___lale")
            },
            nested_base_params,
        )
Ejemplo n.º 7
0
    def test_predict_log_proba_trained_trainable(self):
        from lale.lib.sklearn import BaggingClassifier

        clf = BaggingClassifier()
        clf.fit(self.X_train, self.y_train)
        with self.assertWarns(DeprecationWarning):
            clf.predict_log_proba(self.X_test)
Ejemplo n.º 8
0
    def test_deep_grammar(self):
        from lale.grammar import Grammar
        from lale.lib.sklearn import BaggingClassifier, DecisionTreeClassifier
        from lale.lib.sklearn import KNeighborsClassifier as KNN
        from lale.lib.sklearn import LogisticRegression as LR
        from lale.lib.sklearn import StandardScaler as Scaler

        dtc = DecisionTreeClassifier()
        clf = BaggingClassifier(base_estimator=dtc)
        params = clf.get_params(deep=True)
        filtered_params = self.remove_lale_params(params)

        g = Grammar()
        g.start = g.estimator
        g.estimator = (NoOp | g.transformer) >> g.prim_est
        g.transformer = (NoOp | g.transformer) >> g.prim_tfm

        g.prim_est = LR | KNN
        g.prim_tfm = PCA | Scaler

        params = g.get_params(deep=True)
        filtered_params = self.remove_lale_params(params)
        assert filtered_params["start__name"] == "estimator"
        assert filtered_params["prim_est__LogisticRegression__penalty"] == "l2"
Ejemplo n.º 9
0
 def test_with_lale_pipeline(self):
     from lale.lib.sklearn import BaggingClassifier
     clf = BaggingClassifier(base_estimator=PCA() >> LogisticRegression())
     trained = clf.fit(self.X_train, self.y_train)
     trained.predict(self.X_test)
Ejemplo n.º 10
0
 def test_with_lale_classifiers(self):
     from lale.lib.sklearn import BaggingClassifier
     from lale.sklearn_compat import make_sklearn_compat
     clf = BaggingClassifier(base_estimator=LogisticRegression())
     trained = clf.fit(self.X_train, self.y_train)
     trained.predict(self.X_test)
Ejemplo n.º 11
0
 def test_bagging_in_estimator_mitigation_base(self):
     model = BaggingClassifier(base_estimator=PrejudiceRemover(
         **self.fairness_info))
     self._attempt_fit_predict(model)
Ejemplo n.º 12
0
 def test_bagging_pre_estimator_mitigation_base(self):
     model = BaggingClassifier(base_estimator=DisparateImpactRemover(
         **self.fairness_info) >> DecisionTreeClassifier())
     self._attempt_fit_predict(model)
Ejemplo n.º 13
0
    def test_predict_log_proba_trainable(self):
        from lale.lib.sklearn import BaggingClassifier

        clf = BaggingClassifier(base_estimator=PCA() >> LogisticRegression())
        with self.assertRaises(ValueError):
            clf.predict_log_proba(self.X_test)