Cross-validation estimators

Examples

from fast_automl.cv_estimators import RandomForestClassifierCV

from sklearn.datasets import load_digits
from sklearn.model_selection import cross_val_score, train_test_split

X, y = load_digits(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, stratify=y, shuffle=True)
clf = RandomForestClassifierCV().fit(X_train, y_train, n_jobs=-1)
print('Cross val score: {:.4f}'.format(cross_val_score(clf.best_estimator_, X_train, y_train).mean()))
print('Test score: {:.4f}'.format(clf.score(X_test, y_test)))

Out:

Cross val score: 0.9696
Test score: 0.9800

fast_automl.cv_estimators.CVBaseEstimator

class fast_automl.cv_estimators.CVBaseEstimator(preprocessors=[], param_distributions={}) [source]

Base class for all CV estimators.

Parameters: preprocessors : list, default=[]

Preprocessing steps.

param_distributions : dict, default={}

Maps names of parameters to distributions. This overrides parameters returned by the get_param_distributions method.

Attributes: best_estimator_ : estimator

Estimator which attained the best CV score under randomized search.

best_score_ : scalar

Best CV score attained by any estimator.

cv_results_ : list

List of (mean CV score, parameters) tuples.

Methods

get_param_distributions(self, param_distributions={}) [source]

Parameters: param_distributions : dict, default={}

These are overridden by the param_distributions parameter passed to the constructor.

Returns: param_distributions : dict

Parameter distributions used for randomized search.

make_estimator(self, **params) [source]

fit(category=ConvergenceWarning) def fit(self, X, y, n_iter=10, n_jobs=None, scoring=None) [source]

Fits a CV estimator.

Parameters: X : array-like of shape (n_samples, n_features)

Training data.

y : array-like of shape (n_samples,)

Target values.

n_iter : int, default=10

Number of iterations to use in randomized search.

n_jobs : int or None, default=None

Number of background jobs to use in randomized search.

scoring : str or callable, default=None

A str (see model evaluation documentation) or a scorer callable object / function with signature scorer(estimator, X, y) which should return only a single value. If None, the estimator's default score method is used.

predict(self, X) [source]

Parameters: X : array-like, shape (n_samples, n_features)

Samples.

Returns: C : array, shape (n_samples, n_targets)

Predicted values

predict_proba(self, X) [source]

Probability estimates.

Parameters: X : array-like of shape (n_samples, n_features)

Samples.

Returns: T : array-like of shape (n_samples, n_classes)

Probability of the sample for each classes on the model, ordered by self.classes_.

Notes

Only applicable for classifiers.

fast_automl.cv_estimators.RandomForestClassifierCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.PCARandomForestClassifierCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.RandomForestRegressorCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.PCARandomForestRegressorCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.LogisticLassoCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.PCALogisticLassoCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.LassoLarsCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.PCALassoLarsCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.LogisticRidgeCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.PCALogisticRidgeCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.RidgeCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.PCARidgeCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.LogisticElasticNetCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.PCALogisticElasticNetCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.ElasticNetCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.PCAElasticNetCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.KernelRidgeCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.PCAKernelRidgeCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.SVCCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.PCASVCCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.SVRCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.PCASVRCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.KNeighborsClassifierCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.PCAKNeighborsClassifierCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.KNeighborsRegressorCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.PCAKNeighborsRegressorCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.AdaBoostClassifierCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.PCAAdaBoostClassifierCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.AdaBoostRegressorCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.PCAAdaBoostRegressorCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.XGBClassifierCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.PCAXGBClassifierCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.XGBRegressorCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]

fast_automl.cv_estimators.PCAXGBRegressorCV

Methods

make_estimator(self, **params) [source]

get_param_distributions(self, X, y) [source]