def test_missing_boston(self): # regression, categoricals+numbers, synthetically added missing values all_X, all_y = sklearn.datasets.load_boston(return_X_y=True) with_missing_X = lale.helpers.add_missing_values(all_X) with self.assertRaisesRegex(ValueError, "Input contains NaN"): lr_trainable = LinearRegression() _ = lr_trainable.fit(with_missing_X, all_y) self._fit_predict("regression", with_missing_X, all_y)
def test_scorers_regression(self): fairness_info = self.boston["fairness_info"] trainable = LinearRegression() train_X = self.boston["train_X"] train_y = self.boston["train_y"] trained = trainable.fit(train_X, train_y) test_X = self.boston["test_X"] test_y = self.boston["test_y"] self._attempt_scorers(fairness_info, trained, test_X, test_y)
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_hyperparam_estimator_list(self): lr = LogisticRegression() linear_reg = LinearRegression() dtc = DecisionTreeClassifier() cls_list = [("lr", lr), ("linear_reg", linear_reg)] vc = VotingClassifier(estimators=cls_list) replaced_vc = vc.replace(linear_reg, dtc) new_cls_list = [("lr", lr), ("linear_reg", dtc)] expected_vc = VotingClassifier(estimators=new_cls_list) self.assertEqual(replaced_vc.to_json(), expected_vc.to_json()) sc = StackingClassifier(estimators=cls_list, final_estimator=vc) replaced_sc = sc.replace(linear_reg, dtc) new_cls_list = [("lr", lr), ("linear_reg", dtc)] expected_sc = StackingClassifier( estimators=new_cls_list, final_estimator=expected_vc ) self.assertEqual(replaced_sc.to_json(), expected_sc.to_json())
def test_with_defaults(self): trainable = LinearRegression() trained = trainable.fit(self.train_X, self.train_y) _ = trained.predict(self.test_X)