|
5 | 5 | import dask.distributed |
6 | 6 | import joblib |
7 | 7 | import numpy as np |
8 | | -from sklearn.base import BaseEstimator |
| 8 | +from sklearn.base import BaseEstimator, ClassifierMixin, RegressorMixin |
9 | 9 | from sklearn.utils.multiclass import type_of_target |
10 | 10 |
|
11 | 11 | from autosklearn.automl import AutoMLClassifier, AutoMLRegressor, AutoML |
@@ -219,11 +219,11 @@ def __init__( |
219 | 219 | :meth:`autosklearn.metrics.make_scorer`. These are the `Built-in |
220 | 220 | Metrics`_. |
221 | 221 | If None is provided, a default metric is selected depending on the task. |
222 | | - |
| 222 | +
|
223 | 223 | scoring_functions : List[Scorer], optional (None) |
224 | | - List of scorers which will be calculated for each pipeline and results will be |
| 224 | + List of scorers which will be calculated for each pipeline and results will be |
225 | 225 | available via ``cv_results`` |
226 | | - |
| 226 | +
|
227 | 227 | load_models : bool, optional (True) |
228 | 228 | Whether to load the models after fitting Auto-sklearn. |
229 | 229 |
|
@@ -266,13 +266,14 @@ def __init__( |
266 | 266 | self.smac_scenario_args = smac_scenario_args |
267 | 267 | self.logging_config = logging_config |
268 | 268 | self.metadata_directory = metadata_directory |
269 | | - self._metric = metric |
270 | | - self._scoring_functions = scoring_functions |
271 | | - self._load_models = load_models |
| 269 | + self.metric = metric |
| 270 | + self.scoring_functions = scoring_functions |
| 271 | + self.load_models = load_models |
272 | 272 |
|
273 | 273 | self.automl_ = None # type: Optional[AutoML] |
274 | 274 | # n_jobs after conversion to a number (b/c default is None) |
275 | 275 | self._n_jobs = None |
| 276 | + |
276 | 277 | super().__init__() |
277 | 278 |
|
278 | 279 | def __getstate__(self): |
@@ -323,8 +324,8 @@ def build_automl( |
323 | 324 | smac_scenario_args=smac_scenario_args, |
324 | 325 | logging_config=self.logging_config, |
325 | 326 | metadata_directory=self.metadata_directory, |
326 | | - metric=self._metric, |
327 | | - scoring_functions=self._scoring_functions |
| 327 | + metric=self.metric, |
| 328 | + scoring_functions=self.scoring_functions |
328 | 329 | ) |
329 | 330 |
|
330 | 331 | return automl |
@@ -353,7 +354,7 @@ def fit(self, **kwargs): |
353 | 354 | tmp_folder=self.tmp_folder, |
354 | 355 | output_folder=self.output_folder, |
355 | 356 | ) |
356 | | - self.automl_.fit(load_models=self._load_models, **kwargs) |
| 357 | + self.automl_.fit(load_models=self.load_models, **kwargs) |
357 | 358 |
|
358 | 359 | return self |
359 | 360 |
|
@@ -516,7 +517,7 @@ def get_configuration_space(self, X, y): |
516 | 517 | return self.automl_.configuration_space |
517 | 518 |
|
518 | 519 |
|
519 | | -class AutoSklearnClassifier(AutoSklearnEstimator): |
| 520 | +class AutoSklearnClassifier(AutoSklearnEstimator, ClassifierMixin): |
520 | 521 | """ |
521 | 522 | This class implements the classification task. |
522 | 523 |
|
@@ -597,6 +598,11 @@ def fit(self, X, y, |
597 | 598 | dataset_name=dataset_name, |
598 | 599 | ) |
599 | 600 |
|
| 601 | + # After fit, a classifier is expected to define classes_ |
| 602 | + # A list of class labels known to the classifier, mapping each label |
| 603 | + # to a numerical index used in the model representation our output. |
| 604 | + self.classes_ = self.automl_.InputValidator.target_validator.classes_ |
| 605 | + |
600 | 606 | return self |
601 | 607 |
|
602 | 608 | def predict(self, X, batch_size=None, n_jobs=1): |
@@ -656,7 +662,7 @@ def _get_automl_class(self): |
656 | 662 | return AutoMLClassifier |
657 | 663 |
|
658 | 664 |
|
659 | | -class AutoSklearnRegressor(AutoSklearnEstimator): |
| 665 | +class AutoSklearnRegressor(AutoSklearnEstimator, RegressorMixin): |
660 | 666 | """ |
661 | 667 | This class implements the regression task. |
662 | 668 |
|
|
0 commit comments