diff --git a/autosklearn/automl.py b/autosklearn/automl.py index 09944bec66..f751e87a0a 100644 --- a/autosklearn/automl.py +++ b/autosklearn/automl.py @@ -943,7 +943,7 @@ def predict(self, X, batch_size=None, n_jobs=1): return predicted_classes def predict_proba(self, X, batch_size=None, n_jobs=1): - return self._automl.predict(X, batch_size=batch_size, n_jobs=n_jobs) + return super().predict(X, batch_size=batch_size, n_jobs=n_jobs) class AutoMLRegressor(BaseAutoML): diff --git a/autosklearn/estimators.py b/autosklearn/estimators.py index 1cd600ee2e..96f0a3a5b5 100644 --- a/autosklearn/estimators.py +++ b/autosklearn/estimators.py @@ -308,6 +308,10 @@ def refit(self, X, y): def predict(self, X, batch_size=None, n_jobs=1): return self._automl.predict(X, batch_size=batch_size, n_jobs=n_jobs) + def predict_proba(self, X, batch_size=None, n_jobs=1): + return self._automl.predict_proba( + X, batch_size=batch_size, n_jobs=n_jobs) + def score(self, X, y): return self._automl.score(X, y) @@ -428,7 +432,7 @@ def predict_proba(self, X, batch_size=None, n_jobs=1): The predicted class probabilities. """ - return self._automl.predict_proba( + return super().predict_proba( X, batch_size=batch_size, n_jobs=n_jobs) diff --git a/test/test_automl/test_estimators.py b/test/test_automl/test_estimators.py index 0ba9d68233..2e23f00dd1 100644 --- a/test/test_automl/test_estimators.py +++ b/test/test_automl/test_estimators.py @@ -103,7 +103,6 @@ def test_fit_pSMAC(self): initial_configurations_via_metalearning=0, ensemble_size=0) automl.fit(X_train, Y_train) - # Create a 'dummy model' for the first run, which has an accuracy of # more than 99%; it should be in the final ensemble if the ensemble # building of the second AutoSklearn classifier works correct @@ -303,6 +302,8 @@ def test_multilabel(self): self.assertEqual(predictions.shape, (50, 3)) score = f1_macro(Y_test, predictions) self.assertGreaterEqual(score, 0.9) + probs = automl.predict_proba(X_train) + self.assertAlmostEqual(np.mean(probs), 0.33333333333333331) def test_binary(self): output = os.path.join(self.test_dir, '..', '.tmp_binary_fit') @@ -376,4 +377,4 @@ def test_conversion_of_list_to_np(self, fit_ensemble, refit, fit): self.assertIsInstance(refit.call_args[0][1], np.ndarray) automl.fit_ensemble(y) self.assertEqual(fit_ensemble.call_count, 1) - self.assertIsInstance(fit_ensemble.call_args[0][0], np.ndarray) \ No newline at end of file + self.assertIsInstance(fit_ensemble.call_args[0][0], np.ndarray)