1313from scipy .sparse import spmatrix
1414from sklearn .base import BaseEstimator , ClassifierMixin , RegressorMixin
1515from sklearn .ensemble import VotingClassifier , VotingRegressor
16- from sklearn .exceptions import NotFittedError
1716from sklearn .model_selection ._split import (
1817 BaseCrossValidator ,
1918 BaseShuffleSplit ,
4039
4140# Used to return self and give correct type information from subclasses,
4241# see `fit(self: Self) -> Self`
43- Self = TypeVar ("Self" , bound = AutoSklearnEstimator )
42+ Self = TypeVar ("Self" , bound = " AutoSklearnEstimator" )
4443
4544ResampleOptions : TypeAlias = Literal [
4645 "holdout" ,
5251DisableEvaluatorOptions : TypeAlias = Literal ["y_optimization" , "model" ]
5352
5453
55- class AutoSklearnEstimator (ABC , BaseEstimator , Generic [T_AutoML ]):
54+ class AutoSklearnEstimator (ABC , Generic [T_AutoML ], BaseEstimator ):
5655 def __init__ (
5756 self ,
5857 time_left_for_this_task : int = 3600 ,
@@ -566,8 +565,8 @@ def fit_pipeline(
566565 X_test : SUPPORTED_FEAT_TYPES | None = None ,
567566 y_test : SUPPORTED_TARGET_TYPES | spmatrix | None = None ,
568567 feat_type : list [str ] | None = None ,
569- * args ,
570- ** kwargs : dict ,
568+ * args : Any ,
569+ ** kwargs : Any ,
571570 ) -> tuple [BasePipeline | None , RunInfo , RunValue ]:
572571 """Fits and individual pipeline configuration and returns
573572 the result to the user.
@@ -630,17 +629,17 @@ def fit_pipeline(
630629 )
631630
632631 def fit_ensemble (
633- self ,
634- y ,
635- task : int = None ,
636- precision : Literal [16 , 21 , 64 ] = 32 ,
632+ self : Self ,
633+ y : SUPPORTED_TARGET_TYPES ,
634+ task : int | None = None ,
635+ precision : Literal [16 , 32 , 64 ] = 32 ,
637636 dataset_name : str | None = None ,
638637 ensemble_size : int | None = None ,
639638 ensemble_kwargs : dict [str , Any ] | None = None ,
640639 ensemble_nbest : int | None = None ,
641- ensemble_class : AbstractEnsemble | None = EnsembleSelection ,
640+ ensemble_class : type [ AbstractEnsemble ] | None = EnsembleSelection ,
642641 metrics : Scorer | Sequence [Scorer ] | None = None ,
643- ):
642+ ) -> Self :
644643 """Fit an ensemble to models trained during an optimization process.
645644
646645 All parameters are ``None`` by default. If no other value is given,
@@ -651,19 +650,18 @@ def fit_ensemble(
651650 y : array-like
652651 Target values.
653652
654- task : int
653+ task : int | None = NOne
655654 A constant from the module ``autosklearn.constants``. Determines
656655 the task type (binary classification, multiclass classification,
657656 multilabel classification or regression).
658657
659- precision : int
660- Numeric precision used when loading ensemble data. Can be either
661- ``16``, ``32`` or ``64``.
658+ precision : 16 | 32 | 64 = 32
659+ Numeric precision used when loading ensemble data.
662660
663- dataset_name : str
661+ dataset_name : str | None = None
664662 Name of the current data set.
665663
666- ensemble_size : int, optional
664+ ensemble_size : int | None = None
667665 Number of models added to the ensemble built by *Ensemble
668666 selection from libraries of models*. Models are drawn with
669667 replacement. If set to ``0`` no ensemble is fit.
@@ -672,18 +670,18 @@ def fit_ensemble(
672670 this argument via ``ensemble_kwargs={"ensemble_size": int}``
673671 if you want to change the ensemble size for ensemble selection.
674672
675- ensemble_kwargs : Dict, optional
673+ ensemble_kwargs : dict[str, Any] | None = None
676674 Keyword arguments that are passed to the ensemble class upon
677675 initialization.
678676
679- ensemble_nbest : int
677+ ensemble_nbest : int | None = None
680678 Only consider the ``ensemble_nbest`` models when building an
681679 ensemble. This is inspired by a concept called library pruning
682680 introduced in `Getting Most out of Ensemble Selection`. This
683681 is independent of the ``ensemble_class`` argument and this
684682 pruning step is done prior to constructing an ensemble.
685683
686- ensemble_class : type[AbstractEnsemble], optional (default= EnsembleSelection)
684+ ensemble_class : type[AbstractEnsemble] | None = EnsembleSelection
687685 Class implementing the post-hoc ensemble algorithm. Set to
688686 ``None`` to disable ensemble building or use ``SingleBest``
689687 to obtain only use the single best model instead of an
@@ -700,11 +698,11 @@ def fit_ensemble(
700698 if ensemble_size is not None :
701699 # Keep consistent behaviour
702700 message = (
703- "`ensemble_size` has been deprecated, please use `ensemble_kwargs = "
704- "{ 'ensemble_size': %d} `. Inserting `ensemble_size` into "
705- "`ensemble_kwargs` for now. `ensemble_size` will be removed in "
706- "auto-sklearn 0.16."
707- ) % ensemble_size
701+ "`ensemble_size` has been deprecated, please use `ensemble_kwargs ="
702+ f" {{ 'ensemble_size': { ensemble_size } }} `. Inserting `ensemble_size`"
703+ " into `ensemble_kwargs` for now. `ensemble_size` will be removed in"
704+ " auto-sklearn 0.16."
705+ )
708706 if ensemble_class == EnsembleSelection :
709707 if ensemble_kwargs is None :
710708 ensemble_kwargs = {"ensemble_size" : ensemble_size }
@@ -752,7 +750,7 @@ def fit_ensemble(
752750 )
753751 return self
754752
755- def refit (self , X , y ) :
753+ def refit (self : Self , X : SUPPORTED_FEAT_TYPES , y : SUPPORTED_TARGET_TYPES ) -> Self :
756754 """Refit all models found with fit to new data.
757755
758756 Necessary when using cross-validation. During training, auto-sklearn
@@ -773,21 +771,27 @@ def refit(self, X, y):
773771 Returns
774772 -------
775773 self
776-
777774 """
778775 self .automl_ .refit (X , y )
779776 return self
780777
781- def predict (self , X , batch_size = None , n_jobs = 1 ):
778+ def predict (
779+ self ,
780+ X : SUPPORTED_FEAT_TYPES ,
781+ batch_size : int | None = None ,
782+ n_jobs : int = 1 ,
783+ ) -> np .ndarray :
782784 return self .automl_ .predict (X , batch_size = batch_size , n_jobs = n_jobs )
783785
784- def predict_proba (self , X , batch_size = None , n_jobs = 1 ):
786+ def predict_proba (
787+ self , X : SUPPORTED_FEAT_TYPES , batch_size : int | None = None , n_jobs : int = 1
788+ ) -> np .ndarray :
785789 return self .automl_ .predict_proba (X , batch_size = batch_size , n_jobs = n_jobs )
786790
787- def score (self , X , y ) :
791+ def score (self , X : SUPPORTED_FEAT_TYPES , y : SUPPORTED_TARGET_TYPES ) -> float :
788792 return self .automl_ .score (X , y )
789793
790- def show_models (self ):
794+ def show_models (self ) -> dict :
791795 """Returns a dictionary containing dictionaries of ensemble models.
792796
793797 Each model in the ensemble can be accessed by giving its ``model_id`` as key.
@@ -871,7 +875,7 @@ def show_models(self):
871875
872876 return self .automl_ .show_models ()
873877
874- def get_models_with_weights (self ):
878+ def get_models_with_weights (self ) -> list [ tuple [ float , BasePipeline ]] :
875879 """Return a list of the final ensemble found by auto-sklearn.
876880
877881 Returns
@@ -882,18 +886,18 @@ def get_models_with_weights(self):
882886 return self .automl_ .get_models_with_weights ()
883887
884888 @property
885- def performance_over_time_ (self ):
889+ def performance_over_time_ (self ) -> pd . DataFrame :
886890 return self .automl_ .performance_over_time_
887891
888892 @property
889- def cv_results_ (self ):
893+ def cv_results_ (self ) -> dict [ str , Any ] :
890894 return self .automl_ .cv_results_
891895
892896 @property
893- def trajectory_ (self ):
897+ def trajectory_ (self ) -> np . ndarray :
894898 return self .automl_ .trajectory_
895899
896- def sprint_statistics (self ):
900+ def sprint_statistics (self ) -> str :
897901 """Return the following statistics of the training result:
898902
899903 - dataset name
@@ -1314,15 +1318,15 @@ def _leaderboard_columns(
13141318
13151319 @classmethod
13161320 @abstractmethod
1317- def _get_automl_class (cls ) -> type [AutoML ]:
1321+ def _get_automl_class (cls ) -> type [T_AutoML ]:
13181322 ...
13191323
13201324 def get_configuration_space (
13211325 self ,
13221326 X : SUPPORTED_FEAT_TYPES ,
1323- y : SUPPORTED_TARGET_TYPES | spmatrix ,
1327+ y : SUPPORTED_TARGET_TYPES ,
13241328 X_test : SUPPORTED_FEAT_TYPES | None = None ,
1325- y_test : SUPPORTED_TARGET_TYPES | spmatrix | None = None ,
1329+ y_test : SUPPORTED_TARGET_TYPES | None = None ,
13261330 dataset_name : str | None = None ,
13271331 feat_type : list [str ] | None = None ,
13281332 ) -> ConfigurationSpace :
@@ -1373,12 +1377,12 @@ class AutoSklearnClassifier(AutoSklearnEstimator[AutoMLClassifier], ClassifierMi
13731377
13741378 def fit (
13751379 self : Self ,
1376- X ,
1377- y ,
1378- X_test = None ,
1379- y_test = None ,
1380- feat_type = None ,
1381- dataset_name = None ,
1380+ X : SUPPORTED_FEAT_TYPES ,
1381+ y : SUPPORTED_TARGET_TYPES ,
1382+ X_test : SUPPORTED_FEAT_TYPES | None = None ,
1383+ y_test : SUPPORTED_TARGET_TYPES | None = None ,
1384+ feat_type : list [ str ] | None = None ,
1385+ dataset_name : str | None = None ,
13821386 ) -> Self :
13831387 """Fit *auto-sklearn* to given training set (X, y).
13841388
@@ -1456,7 +1460,12 @@ def fit(
14561460
14571461 return self
14581462
1459- def predict (self , X , batch_size = None , n_jobs = 1 ):
1463+ def predict (
1464+ self ,
1465+ X : SUPPORTED_FEAT_TYPES ,
1466+ batch_size : int | None = None ,
1467+ n_jobs : int = 1 ,
1468+ ) -> np .ndarray :
14601469 """Predict classes for X.
14611470
14621471 Parameters
@@ -1470,7 +1479,12 @@ def predict(self, X, batch_size=None, n_jobs=1):
14701479 """
14711480 return super ().predict (X , batch_size = batch_size , n_jobs = n_jobs )
14721481
1473- def predict_proba (self , X , batch_size = None , n_jobs = 1 ):
1482+ def predict_proba (
1483+ self ,
1484+ X : SUPPORTED_FEAT_TYPES ,
1485+ batch_size : int | None = None ,
1486+ n_jobs : int = 1 ,
1487+ ) -> np .ndarray :
14741488 """Predict probabilities of classes for all samples X.
14751489
14761490 Parameters
@@ -1503,7 +1517,8 @@ def predict_proba(self, X, batch_size=None, n_jobs=1):
15031517
15041518 return pred_proba
15051519
1506- def _get_automl_class (self ):
1520+ @classmethod
1521+ def _get_automl_class (cls ) -> type [AutoMLClassifier ]:
15071522 return AutoMLClassifier
15081523
15091524
@@ -1515,12 +1530,12 @@ class AutoSklearnRegressor(AutoSklearnEstimator[AutoMLRegressor], RegressorMixin
15151530
15161531 def fit (
15171532 self : Self ,
1518- X ,
1519- y ,
1520- X_test = None ,
1521- y_test = None ,
1522- feat_type = None ,
1523- dataset_name = None ,
1533+ X : SUPPORTED_FEAT_TYPES ,
1534+ y : SUPPORTED_TARGET_TYPES ,
1535+ X_test : SUPPORTED_FEAT_TYPES | None = None ,
1536+ y_test : SUPPORTED_TARGET_TYPES | None = None ,
1537+ feat_type : list [ str ] | None = None ,
1538+ dataset_name : str | None = None ,
15241539 ) -> Self :
15251540 """Fit *Auto-sklearn* to given training set (X, y).
15261541
@@ -1597,7 +1612,12 @@ def fit(
15971612
15981613 return self
15991614
1600- def predict (self , X , batch_size = None , n_jobs = 1 ):
1615+ def predict (
1616+ self ,
1617+ X : SUPPORTED_FEAT_TYPES ,
1618+ batch_size : int | None = None ,
1619+ n_jobs : int = 1 ,
1620+ ) -> np .ndarray :
16011621 """Predict regression target for X.
16021622
16031623 Parameters
0 commit comments