Skip to content

Commit 43eb3d8

Browse files
authored
Merge pull request #411 from mabryj2/fix/proba-inherit
Fix predict_proba for classifer
2 parents 2c4eb9d + 0d10f7b commit 43eb3d8

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

autosklearn/automl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ def predict(self, X, batch_size=None, n_jobs=1):
943943
return predicted_classes
944944

945945
def predict_proba(self, X, batch_size=None, n_jobs=1):
946-
return self._automl.predict(X, batch_size=batch_size, n_jobs=n_jobs)
946+
return super().predict(X, batch_size=batch_size, n_jobs=n_jobs)
947947

948948

949949
class AutoMLRegressor(BaseAutoML):

autosklearn/estimators.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ def refit(self, X, y):
308308
def predict(self, X, batch_size=None, n_jobs=1):
309309
return self._automl.predict(X, batch_size=batch_size, n_jobs=n_jobs)
310310

311+
def predict_proba(self, X, batch_size=None, n_jobs=1):
312+
return self._automl.predict_proba(
313+
X, batch_size=batch_size, n_jobs=n_jobs)
314+
311315
def score(self, X, y):
312316
return self._automl.score(X, y)
313317

@@ -428,7 +432,7 @@ def predict_proba(self, X, batch_size=None, n_jobs=1):
428432
The predicted class probabilities.
429433
430434
"""
431-
return self._automl.predict_proba(
435+
return super().predict_proba(
432436
X, batch_size=batch_size, n_jobs=n_jobs)
433437

434438

test/test_automl/test_estimators.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ def test_fit_pSMAC(self):
103103
initial_configurations_via_metalearning=0,
104104
ensemble_size=0)
105105
automl.fit(X_train, Y_train)
106-
107106
# Create a 'dummy model' for the first run, which has an accuracy of
108107
# more than 99%; it should be in the final ensemble if the ensemble
109108
# building of the second AutoSklearn classifier works correct
@@ -303,6 +302,8 @@ def test_multilabel(self):
303302
self.assertEqual(predictions.shape, (50, 3))
304303
score = f1_macro(Y_test, predictions)
305304
self.assertGreaterEqual(score, 0.9)
305+
probs = automl.predict_proba(X_train)
306+
self.assertAlmostEqual(np.mean(probs), 0.33333333333333331)
306307

307308
def test_binary(self):
308309
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):
376377
self.assertIsInstance(refit.call_args[0][1], np.ndarray)
377378
automl.fit_ensemble(y)
378379
self.assertEqual(fit_ensemble.call_count, 1)
379-
self.assertIsInstance(fit_ensemble.call_args[0][0], np.ndarray)
380+
self.assertIsInstance(fit_ensemble.call_args[0][0], np.ndarray)

0 commit comments

Comments
 (0)