Feature ranking with recursive feature elimination and cross-validated selection of the best number of features.
See glossary entry for cross-validation estimator.
Read more in the User Guide.
A supervised learning estimator with a fit method that provides information about feature importance either through a coef_ attribute or through a feature_importances_ attribute.
If greater than or equal to 1, then step corresponds to the (integer) number of features to remove at each iteration. If within (0.0, 1.0), then step corresponds to the percentage (rounded down) of features to remove at each iteration. Note that the last iteration may remove fewer than step features in order to reach min_features_to_select.
The minimum number of features to be selected. This number of features will always be scored, even if the difference between the original feature count and min_features_to_select isn’t divisible by step.
New in version 0.20.
Determines the cross-validation splitting strategy. Possible inputs for cv are:
For integer/None inputs, if y is binary or multiclass, StratifiedKFold is used. If the estimator is a classifier or if y is neither binary nor multiclass, KFold is used.
Refer User Guide for the various cross-validation strategies that can be used here.
Changed in version 0.22: cv default value of None changed from 3-fold to 5-fold.
A string (see model evaluation documentation) or a scorer callable object / function with signature scorer(estimator, X, y).
Controls verbosity of output.
Number of cores to run in parallel while fitting across folds. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
New in version 0.18.
If ‘auto’, uses the feature importance either through a coef_ or feature_importances_ attributes of estimator.
Also accepts a string that specifies an attribute name/path for extracting feature importance. For example, give regressor_.coef_ in case of TransformedTargetRegressor or named_steps.clf.feature_importances_ in case of Pipeline with its last step named clf.
If callable, overrides the default feature importance getter. The callable is passed with the fitted estimator and it should return importance for each feature.
New in version 0.24.
The fitted estimator used to select features.
The cross-validation scores such that grid_scores_[i] corresponds to the CV score of the i-th subset of features.
The number of selected features with cross-validation.
The feature ranking, such that ranking_[i] corresponds to the ranking position of the i-th feature. Selected (i.e., estimated best) features are assigned rank 1.
The mask of selected features.
See also
Recursive feature elimination.
The size of grid_scores_ is equal to ceil((n_features - min_features_to_select) / step) + 1, where step is the number of features removed at each iteration.
Allows NaN/Inf in the input if the underlying estimator does as well.
Guyon, I., Weston, J., Barnhill, S., & Vapnik, V., “Gene selection for cancer classification using support vector machines”, Mach. Learn., 46(1-3), 389–422, 2002.
The following example shows how to retrieve the a-priori not known 5 informative features in the Friedman #1 dataset.
decision_function(X)
Compute the decision function of X.
fit(X, y[, groups])
Fit the RFE model and automatically tune the number of selected
fit_transform(X[, y])
Fit to data, then transform it.
get_params([deep])
Get parameters for this estimator.
get_support([indices])
Get a mask, or integer index, of the features selected
inverse_transform(X)
Reverse the transformation operation
predict(X)
Reduce X to the selected features and then predict using the
predict_log_proba(X)
Predict class log-probabilities for X.
predict_proba(X)
Predict class probabilities for X.
score(X, y)
Reduce X to the selected features and then return the score of the
set_params(**params)
Set the parameters of this estimator.
transform(X)
Reduce X to the selected features.
Compute the decision function of X.
The input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr_matrix.
The decision function of the input samples. The order of the classes corresponds to that in the attribute classes_. Regression and binary classification produce an array of shape [n_samples].
features.
Training vector, where n_samples is the number of samples and n_features is the total number of features.
Target values (integers for classification, real numbers for regression).
Group labels for the samples used while splitting the dataset into train/test set. Only used in conjunction with a “Group” cv instance (e.g., GroupKFold).
New in version 0.20.
Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
Input samples.
Target values (None for unsupervised transformations).
Additional fit parameters.
Transformed array.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Get a mask, or integer index, of the features selected
If True, the return value will be an array of integers, rather than a boolean mask.
An index that selects the retained features from a feature vector. If indices is False, this is a boolean array of shape [# input features], in which an element is True iff its corresponding feature is selected for retention. If indices is True, this is an integer array of shape [# output features] whose values are indices into the input feature vector.
Reverse the transformation operation
The input samples.
X with columns of zeros inserted where features would have been removed by transform.
underlying estimator.
The input samples.
The predicted target values.
Predict class log-probabilities for X.
The input samples.
The class log-probabilities of the input samples. The order of the classes corresponds to that in the attribute classes_.
Predict class probabilities for X.
The input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr_matrix.
The class probabilities of the input samples. The order of the classes corresponds to that in the attribute classes_.
underlying estimator.
The input samples.
The target values.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Reduce X to the selected features.
The input samples.
The input samples with only the selected features.


Feature ranking with recursive feature elimination and cross-validated selection of the best number of features.
See glossary entry for cross-validation estimator.
Read more in the User Guide.
A supervised learning estimator with a fit method that provides information about feature importance either through a coef_ attribute or through a feature_importances_ attribute.
If greater than or equal to 1, then step corresponds to the (integer) number of features to remove at each iteration. If within (0.0, 1.0), then step corresponds to the percentage (rounded down) of features to remove at each iteration. Note that the last iteration may remove fewer than step features in order to reach min_features_to_select.
The minimum number of features to be selected. This number of features will always be scored, even if the difference between the original feature count and min_features_to_select isn’t divisible by step.
New in version 0.20.
Determines the cross-validation splitting strategy. Possible inputs for cv are:
For integer/None inputs, if y is binary or multiclass, StratifiedKFold is used. If the estimator is a classifier or if y is neither binary nor multiclass, KFold is used.
Refer User Guide for the various cross-validation strategies that can be used here.
Changed in version 0.22: cv default value of None changed from 3-fold to 5-fold.
A string (see model evaluation documentation) or a scorer callable object / function with signature scorer(estimator, X, y).
Controls verbosity of output.
Number of cores to run in parallel while fitting across folds. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
New in version 0.18.
If ‘auto’, uses the feature importance either through a coef_ or feature_importances_ attributes of estimator.
Also accepts a string that specifies an attribute name/path for extracting feature importance. For example, give regressor_.coef_ in case of TransformedTargetRegressor or named_steps.clf.feature_importances_ in case of Pipeline with its last step named clf.
If callable, overrides the default feature importance getter. The callable is passed with the fitted estimator and it should return importance for each feature.
New in version 0.24.
The fitted estimator used to select features.
The cross-validation scores such that grid_scores_[i] corresponds to the CV score of the i-th subset of features.
The number of selected features with cross-validation.
The feature ranking, such that ranking_[i] corresponds to the ranking position of the i-th feature. Selected (i.e., estimated best) features are assigned rank 1.
The mask of selected features.
See also
Recursive feature elimination.
The size of grid_scores_ is equal to ceil((n_features - min_features_to_select) / step) + 1, where step is the number of features removed at each iteration.
Allows NaN/Inf in the input if the underlying estimator does as well.
Guyon, I., Weston, J., Barnhill, S., & Vapnik, V., “Gene selection for cancer classification using support vector machines”, Mach. Learn., 46(1-3), 389–422, 2002.
The following example shows how to retrieve the a-priori not known 5 informative features in the Friedman #1 dataset.
decision_function(X)
Compute the decision function of X.
fit(X, y[, groups])
Fit the RFE model and automatically tune the number of selected
fit_transform(X[, y])
Fit to data, then transform it.
get_params([deep])
Get parameters for this estimator.
get_support([indices])
Get a mask, or integer index, of the features selected
inverse_transform(X)
Reverse the transformation operation
predict(X)
Reduce X to the selected features and then predict using the
predict_log_proba(X)
Predict class log-probabilities for X.
predict_proba(X)
Predict class probabilities for X.
score(X, y)
Reduce X to the selected features and then return the score of the
set_params(**params)
Set the parameters of this estimator.
transform(X)
Reduce X to the selected features.
Compute the decision function of X.
The input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr_matrix.
The decision function of the input samples. The order of the classes corresponds to that in the attribute classes_. Regression and binary classification produce an array of shape [n_samples].
features.
Training vector, where n_samples is the number of samples and n_features is the total number of features.
Target values (integers for classification, real numbers for regression).
Group labels for the samples used while splitting the dataset into train/test set. Only used in conjunction with a “Group” cv instance (e.g., GroupKFold).
New in version 0.20.
Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
Input samples.
Target values (None for unsupervised transformations).
Additional fit parameters.
Transformed array.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Get a mask, or integer index, of the features selected
If True, the return value will be an array of integers, rather than a boolean mask.
An index that selects the retained features from a feature vector. If indices is False, this is a boolean array of shape [# input features], in which an element is True iff its corresponding feature is selected for retention. If indices is True, this is an integer array of shape [# output features] whose values are indices into the input feature vector.
Reverse the transformation operation
The input samples.
X with columns of zeros inserted where features would have been removed by transform.
underlying estimator.
The input samples.
The predicted target values.
Predict class log-probabilities for X.
The input samples.
The class log-probabilities of the input samples. The order of the classes corresponds to that in the attribute classes_.
Predict class probabilities for X.
The input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr_matrix.
The class probabilities of the input samples. The order of the classes corresponds to that in the attribute classes_.
underlying estimator.
The input samples.
The target values.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Reduce X to the selected features.
The input samples.
The input samples with only the selected features.
Recursive feature elimination with cross-validation


Compute the decision function of X.
The input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr_matrix.
The decision function of the input samples. The order of the classes corresponds to that in the attribute classes_. Regression and binary classification produce an array of shape [n_samples].


features.
Training vector, where n_samples is the number of samples and n_features is the total number of features.
Target values (integers for classification, real numbers for regression).
Group labels for the samples used while splitting the dataset into train/test set. Only used in conjunction with a “Group” cv instance (e.g., GroupKFold).
New in version 0.20.


Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
Input samples.
Target values (None for unsupervised transformations).
Additional fit parameters.
Transformed array.


Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.


Get a mask, or integer index, of the features selected
If True, the return value will be an array of integers, rather than a boolean mask.
An index that selects the retained features from a feature vector. If indices is False, this is a boolean array of shape [# input features], in which an element is True iff its corresponding feature is selected for retention. If indices is True, this is an integer array of shape [# output features] whose values are indices into the input feature vector.


Reverse the transformation operation
The input samples.
X with columns of zeros inserted where features would have been removed by transform.


underlying estimator.
The input samples.
The predicted target values.


Predict class log-probabilities for X.
The input samples.
The class log-probabilities of the input samples. The order of the classes corresponds to that in the attribute classes_.


Predict class probabilities for X.
The input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr_matrix.
The class probabilities of the input samples. The order of the classes corresponds to that in the attribute classes_.


underlying estimator.
The input samples.
The target values.


Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.


Reduce X to the selected features.
The input samples.
The input samples with only the selected features.


Filter: Select the p-values for an estimated false discovery rate
This uses the Benjamini-Hochberg procedure. alpha is an upper bound on the expected false discovery rate.
Read more in the User Guide.
Function taking two arrays X and y, and returning a pair of arrays (scores, pvalues). Default is f_classif (see below “See Also”). The default function only works with classification tasks.
The highest uncorrected p-value for features to keep.
Scores of features.
p-values of feature scores.
See also
ANOVA F-value between label/feature for classification tasks.
Mutual information for a discrete target.
Chi-squared stats of non-negative features for classification tasks.
F-value between label/feature for regression tasks.
Mutual information for a contnuous target.
Select features based on percentile of the highest scores.
Select features based on the k highest scores.
Select features based on a false positive rate test.
Select features based on family-wise error rate.
Univariate feature selector with configurable mode.
https://en.wikipedia.org/wiki/False_discovery_rate
fit(X, y)
Run score function on (X, y) and get the appropriate features.
fit_transform(X[, y])
Fit to data, then transform it.
get_params([deep])
Get parameters for this estimator.
get_support([indices])
Get a mask, or integer index, of the features selected
inverse_transform(X)
Reverse the transformation operation
set_params(**params)
Set the parameters of this estimator.
transform(X)
Reduce X to the selected features.
Run score function on (X, y) and get the appropriate features.
The training input samples.
The target values (class labels in classification, real numbers in regression).
Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
Input samples.
Target values (None for unsupervised transformations).
Additional fit parameters.
Transformed array.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Get a mask, or integer index, of the features selected
If True, the return value will be an array of integers, rather than a boolean mask.
An index that selects the retained features from a feature vector. If indices is False, this is a boolean array of shape [# input features], in which an element is True iff its corresponding feature is selected for retention. If indices is True, this is an integer array of shape [# output features] whose values are indices into the input feature vector.
Reverse the transformation operation
The input samples.
X with columns of zeros inserted where features would have been removed by transform.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Reduce X to the selected features.
The input samples.
The input samples with only the selected features.


Run score function on (X, y) and get the appropriate features.
The training input samples.
The target values (class labels in classification, real numbers in regression).


Filter: Select the pvalues below alpha based on a FPR test.
FPR test stands for False Positive Rate test. It controls the total amount of false detections.
Read more in the User Guide.
Function taking two arrays X and y, and returning a pair of arrays (scores, pvalues). Default is f_classif (see below “See Also”). The default function only works with classification tasks.
The highest p-value for features to be kept.
Scores of features.
p-values of feature scores.
See also
ANOVA F-value between label/feature for classification tasks.
Chi-squared stats of non-negative features for classification tasks.
Mutual information for a discrete target.
F-value between label/feature for regression tasks.
Mutual information for a continuous target.
Select features based on percentile of the highest scores.
Select features based on the k highest scores.
Select features based on an estimated false discovery rate.
Select features based on family-wise error rate.
Univariate feature selector with configurable mode.
fit(X, y)
Run score function on (X, y) and get the appropriate features.
fit_transform(X[, y])
Fit to data, then transform it.
get_params([deep])
Get parameters for this estimator.
get_support([indices])
Get a mask, or integer index, of the features selected
inverse_transform(X)
Reverse the transformation operation
set_params(**params)
Set the parameters of this estimator.
transform(X)
Reduce X to the selected features.
Run score function on (X, y) and get the appropriate features.
The training input samples.
The target values (class labels in classification, real numbers in regression).
Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
Input samples.
Target values (None for unsupervised transformations).
Additional fit parameters.
Transformed array.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Get a mask, or integer index, of the features selected
If True, the return value will be an array of integers, rather than a boolean mask.
An index that selects the retained features from a feature vector. If indices is False, this is a boolean array of shape [# input features], in which an element is True iff its corresponding feature is selected for retention. If indices is True, this is an integer array of shape [# output features] whose values are indices into the input feature vector.
Reverse the transformation operation
The input samples.
X with columns of zeros inserted where features would have been removed by transform.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Reduce X to the selected features.
The input samples.
The input samples with only the selected features.


Meta-transformer for selecting features based on importance weights.
New in version 0.17.
Read more in the User Guide.
The base estimator from which the transformer is built. This can be both a fitted (if prefit is set to True) or a non-fitted estimator. The estimator must have either a feature_importances_ or coef_ attribute after fitting.
The threshold value to use for feature selection. Features whose importance is greater or equal are kept while the others are discarded. If “median” (resp. “mean”), then the threshold value is the median (resp. the mean) of the feature importances. A scaling factor (e.g., “1.25*mean”) may also be used. If None and if the estimator has a parameter penalty set to l1, either explicitly or implicitly (e.g, Lasso), the threshold used is 1e-5. Otherwise, “mean” is used by default.
Whether a prefit model is expected to be passed into the constructor directly or not. If True, transform must be called directly and SelectFromModel cannot be used with cross_val_score, GridSearchCV and similar utilities that clone the estimator. Otherwise train the model using fit and then transform to do feature selection.
Order of the norm used to filter the vectors of coefficients below threshold in the case where the coef_ attribute of the estimator is of dimension 2.
The maximum number of features to select. To only select based on max_features, set threshold=-np.inf.
New in version 0.20.
If ‘auto’, uses the feature importance either through a coef_ attribute or feature_importances_ attribute of estimator.
Also accepts a string that specifies an attribute name/path for extracting feature importance (implemented with attrgetter). For example, give regressor_.coef_ in case of TransformedTargetRegressor or named_steps.clf.feature_importances_ in case of Pipeline with its last step named clf.
If callable, overrides the default feature importance getter. The callable is passed with the fitted estimator and it should return importance for each feature.
New in version 0.24.
The base estimator from which the transformer is built. This is stored only when a non-fitted estimator is passed to the SelectFromModel, i.e when prefit is False.
The threshold value used for feature selection.
See also
Recursive feature elimination based on importance weights.
Recursive feature elimination with built-in cross-validated selection of the best number of features.
Sequential cross-validation based feature selection. Does not rely on importance weights.
Allows NaN/Inf in the input if the underlying estimator does as well.
fit(X[, y])
Fit the SelectFromModel meta-transformer.
fit_transform(X[, y])
Fit to data, then transform it.
get_params([deep])
Get parameters for this estimator.
get_support([indices])
Get a mask, or integer index, of the features selected
inverse_transform(X)
Reverse the transformation operation
partial_fit(X[, y])
Fit the SelectFromModel meta-transformer only once.
set_params(**params)
Set the parameters of this estimator.
transform(X)
Reduce X to the selected features.
Fit the SelectFromModel meta-transformer.
The training input samples.
The target values (integers that correspond to classes in classification, real numbers in regression).
Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
Input samples.
Target values (None for unsupervised transformations).
Additional fit parameters.
Transformed array.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Get a mask, or integer index, of the features selected
If True, the return value will be an array of integers, rather than a boolean mask.
An index that selects the retained features from a feature vector. If indices is False, this is a boolean array of shape [# input features], in which an element is True iff its corresponding feature is selected for retention. If indices is True, this is an integer array of shape [# output features] whose values are indices into the input feature vector.
Reverse the transformation operation
The input samples.
X with columns of zeros inserted where features would have been removed by transform.
Fit the SelectFromModel meta-transformer only once.
The training input samples.
The target values (integers that correspond to classes in classification, real numbers in regression).
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Reduce X to the selected features.
The input samples.
The input samples with only the selected features.


Meta-transformer for selecting features based on importance weights.
New in version 0.17.
Read more in the User Guide.
The base estimator from which the transformer is built. This can be both a fitted (if prefit is set to True) or a non-fitted estimator. The estimator must have either a feature_importances_ or coef_ attribute after fitting.
The threshold value to use for feature selection. Features whose importance is greater or equal are kept while the others are discarded. If “median” (resp. “mean”), then the threshold value is the median (resp. the mean) of the feature importances. A scaling factor (e.g., “1.25*mean”) may also be used. If None and if the estimator has a parameter penalty set to l1, either explicitly or implicitly (e.g, Lasso), the threshold used is 1e-5. Otherwise, “mean” is used by default.
Whether a prefit model is expected to be passed into the constructor directly or not. If True, transform must be called directly and SelectFromModel cannot be used with cross_val_score, GridSearchCV and similar utilities that clone the estimator. Otherwise train the model using fit and then transform to do feature selection.
Order of the norm used to filter the vectors of coefficients below threshold in the case where the coef_ attribute of the estimator is of dimension 2.
The maximum number of features to select. To only select based on max_features, set threshold=-np.inf.
New in version 0.20.
If ‘auto’, uses the feature importance either through a coef_ attribute or feature_importances_ attribute of estimator.
Also accepts a string that specifies an attribute name/path for extracting feature importance (implemented with attrgetter). For example, give regressor_.coef_ in case of TransformedTargetRegressor or named_steps.clf.feature_importances_ in case of Pipeline with its last step named clf.
If callable, overrides the default feature importance getter. The callable is passed with the fitted estimator and it should return importance for each feature.
New in version 0.24.
The base estimator from which the transformer is built. This is stored only when a non-fitted estimator is passed to the SelectFromModel, i.e when prefit is False.
The threshold value used for feature selection.
See also
Recursive feature elimination based on importance weights.
Recursive feature elimination with built-in cross-validated selection of the best number of features.
Sequential cross-validation based feature selection. Does not rely on importance weights.
Allows NaN/Inf in the input if the underlying estimator does as well.
fit(X[, y])
Fit the SelectFromModel meta-transformer.
fit_transform(X[, y])
Fit to data, then transform it.
get_params([deep])
Get parameters for this estimator.
get_support([indices])
Get a mask, or integer index, of the features selected
inverse_transform(X)
Reverse the transformation operation
partial_fit(X[, y])
Fit the SelectFromModel meta-transformer only once.
set_params(**params)
Set the parameters of this estimator.
transform(X)
Reduce X to the selected features.
Fit the SelectFromModel meta-transformer.
The training input samples.
The target values (integers that correspond to classes in classification, real numbers in regression).
Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
Input samples.
Target values (None for unsupervised transformations).
Additional fit parameters.
Transformed array.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Get a mask, or integer index, of the features selected
If True, the return value will be an array of integers, rather than a boolean mask.
An index that selects the retained features from a feature vector. If indices is False, this is a boolean array of shape [# input features], in which an element is True iff its corresponding feature is selected for retention. If indices is True, this is an integer array of shape [# output features] whose values are indices into the input feature vector.
Reverse the transformation operation
The input samples.
X with columns of zeros inserted where features would have been removed by transform.
Fit the SelectFromModel meta-transformer only once.
The training input samples.
The target values (integers that correspond to classes in classification, real numbers in regression).
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Reduce X to the selected features.
The input samples.
The input samples with only the selected features.
Model-based and sequential feature selection
Classification of text documents using sparse features


Fit the SelectFromModel meta-transformer.
The training input samples.
The target values (integers that correspond to classes in classification, real numbers in regression).


Fit the SelectFromModel meta-transformer only once.
The training input samples.
The target values (integers that correspond to classes in classification, real numbers in regression).


Filter: Select the p-values corresponding to Family-wise error rate
Read more in the User Guide.
Function taking two arrays X and y, and returning a pair of arrays (scores, pvalues). Default is f_classif (see below “See Also”). The default function only works with classification tasks.
The highest uncorrected p-value for features to keep.
Scores of features.
p-values of feature scores.
See also
ANOVA F-value between label/feature for classification tasks.
Chi-squared stats of non-negative features for classification tasks.
F-value between label/feature for regression tasks.
Select features based on percentile of the highest scores.
Select features based on the k highest scores.
Select features based on a false positive rate test.
Select features based on an estimated false discovery rate.
Univariate feature selector with configurable mode.
fit(X, y)
Run score function on (X, y) and get the appropriate features.
fit_transform(X[, y])
Fit to data, then transform it.
get_params([deep])
Get parameters for this estimator.
get_support([indices])
Get a mask, or integer index, of the features selected
inverse_transform(X)
Reverse the transformation operation
set_params(**params)
Set the parameters of this estimator.
transform(X)
Reduce X to the selected features.
Run score function on (X, y) and get the appropriate features.
The training input samples.
The target values (class labels in classification, real numbers in regression).
Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
Input samples.
Target values (None for unsupervised transformations).
Additional fit parameters.
Transformed array.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Get a mask, or integer index, of the features selected
If True, the return value will be an array of integers, rather than a boolean mask.
An index that selects the retained features from a feature vector. If indices is False, this is a boolean array of shape [# input features], in which an element is True iff its corresponding feature is selected for retention. If indices is True, this is an integer array of shape [# output features] whose values are indices into the input feature vector.
Reverse the transformation operation
The input samples.
X with columns of zeros inserted where features would have been removed by transform.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Reduce X to the selected features.
The input samples.
The input samples with only the selected features.


Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
Input samples.
Target values (None for unsupervised transformations).
Additional fit parameters.
Transformed array.


Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.


Get a mask, or integer index, of the features selected
If True, the return value will be an array of integers, rather than a boolean mask.
An index that selects the retained features from a feature vector. If indices is False, this is a boolean array of shape [# input features], in which an element is True iff its corresponding feature is selected for retention. If indices is True, this is an integer array of shape [# output features] whose values are indices into the input feature vector.


Reverse the transformation operation
The input samples.
X with columns of zeros inserted where features would have been removed by transform.


Select features according to the k highest scores.
Read more in the User Guide.
Function taking two arrays X and y, and returning a pair of arrays (scores, pvalues) or a single array with scores. Default is f_classif (see below “See Also”). The default function only works with classification tasks.
New in version 0.18.
Number of top features to select. The “all” option bypasses selection, for use in a parameter search.
Scores of features.
p-values of feature scores, None if score_func returned only scores.
See also
ANOVA F-value between label/feature for classification tasks.
Mutual information for a discrete target.
Chi-squared stats of non-negative features for classification tasks.
F-value between label/feature for regression tasks.
Mutual information for a continuous target.
Select features based on percentile of the highest scores.
Select features based on a false positive rate test.
Select features based on an estimated false discovery rate.
Select features based on family-wise error rate.
Univariate feature selector with configurable mode.
Ties between features with equal scores will be broken in an unspecified way.
fit(X, y)
Run score function on (X, y) and get the appropriate features.
fit_transform(X[, y])
Fit to data, then transform it.
get_params([deep])
Get parameters for this estimator.
get_support([indices])
Get a mask, or integer index, of the features selected
inverse_transform(X)
Reverse the transformation operation
set_params(**params)
Set the parameters of this estimator.
transform(X)
Reduce X to the selected features.
Run score function on (X, y) and get the appropriate features.
The training input samples.
The target values (class labels in classification, real numbers in regression).
Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
Input samples.
Target values (None for unsupervised transformations).
Additional fit parameters.
Transformed array.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Get a mask, or integer index, of the features selected
If True, the return value will be an array of integers, rather than a boolean mask.
An index that selects the retained features from a feature vector. If indices is False, this is a boolean array of shape [# input features], in which an element is True iff its corresponding feature is selected for retention. If indices is True, this is an integer array of shape [# output features] whose values are indices into the input feature vector.
Reverse the transformation operation
The input samples.
X with columns of zeros inserted where features would have been removed by transform.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Reduce X to the selected features.
The input samples.
The input samples with only the selected features.


Select features according to the k highest scores.
Read more in the User Guide.
Function taking two arrays X and y, and returning a pair of arrays (scores, pvalues) or a single array with scores. Default is f_classif (see below “See Also”). The default function only works with classification tasks.
New in version 0.18.
Number of top features to select. The “all” option bypasses selection, for use in a parameter search.
Scores of features.
p-values of feature scores, None if score_func returned only scores.
See also
ANOVA F-value between label/feature for classification tasks.
Mutual information for a discrete target.
Chi-squared stats of non-negative features for classification tasks.
F-value between label/feature for regression tasks.
Mutual information for a continuous target.
Select features based on percentile of the highest scores.
Select features based on a false positive rate test.
Select features based on an estimated false discovery rate.
Select features based on family-wise error rate.
Univariate feature selector with configurable mode.
Ties between features with equal scores will be broken in an unspecified way.
fit(X, y)
Run score function on (X, y) and get the appropriate features.
fit_transform(X[, y])
Fit to data, then transform it.
get_params([deep])
Get parameters for this estimator.
get_support([indices])
Get a mask, or integer index, of the features selected
inverse_transform(X)
Reverse the transformation operation
set_params(**params)
Set the parameters of this estimator.
transform(X)
Reduce X to the selected features.
Run score function on (X, y) and get the appropriate features.
The training input samples.
The target values (class labels in classification, real numbers in regression).
Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
Input samples.
Target values (None for unsupervised transformations).
Additional fit parameters.
Transformed array.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Get a mask, or integer index, of the features selected
If True, the return value will be an array of integers, rather than a boolean mask.
An index that selects the retained features from a feature vector. If indices is False, this is a boolean array of shape [# input features], in which an element is True iff its corresponding feature is selected for retention. If indices is True, this is an integer array of shape [# output features] whose values are indices into the input feature vector.
Reverse the transformation operation
The input samples.
X with columns of zeros inserted where features would have been removed by transform.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Reduce X to the selected features.
The input samples.
The input samples with only the selected features.
Pipeline Anova SVM
Univariate Feature Selection
Concatenating multiple feature extraction methods
Selecting dimensionality reduction with Pipeline and GridSearchCV
Classification of text documents using sparse features


Transformer mixin that performs feature selection given a support mask
This mixin provides a feature selector implementation with transform and inverse_transform functionality given an implementation of _get_support_mask.
fit_transform(X[, y])
Fit to data, then transform it.
get_support([indices])
Get a mask, or integer index, of the features selected
inverse_transform(X)
Reverse the transformation operation
transform(X)
Reduce X to the selected features.
Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
Input samples.
Target values (None for unsupervised transformations).
Additional fit parameters.
Transformed array.
Get a mask, or integer index, of the features selected
If True, the return value will be an array of integers, rather than a boolean mask.
An index that selects the retained features from a feature vector. If indices is False, this is a boolean array of shape [# input features], in which an element is True iff its corresponding feature is selected for retention. If indices is True, this is an integer array of shape [# output features] whose values are indices into the input feature vector.
Reverse the transformation operation
The input samples.
X with columns of zeros inserted where features would have been removed by transform.
Reduce X to the selected features.
The input samples.
The input samples with only the selected features.


Select features according to a percentile of the highest scores.
Read more in the User Guide.
Function taking two arrays X and y, and returning a pair of arrays (scores, pvalues) or a single array with scores. Default is f_classif (see below “See Also”). The default function only works with classification tasks.
New in version 0.18.
Percent of features to keep.
Scores of features.
p-values of feature scores, None if score_func returned only scores.
See also
ANOVA F-value between label/feature for classification tasks.
Mutual information for a discrete target.
Chi-squared stats of non-negative features for classification tasks.
F-value between label/feature for regression tasks.
Mutual information for a continuous target.
Select features based on the k highest scores.
Select features based on a false positive rate test.
Select features based on an estimated false discovery rate.
Select features based on family-wise error rate.
Univariate feature selector with configurable mode.
Ties between features with equal scores will be broken in an unspecified way.
fit(X, y)
Run score function on (X, y) and get the appropriate features.
fit_transform(X[, y])
Fit to data, then transform it.
get_params([deep])
Get parameters for this estimator.
get_support([indices])
Get a mask, or integer index, of the features selected
inverse_transform(X)
Reverse the transformation operation
set_params(**params)
Set the parameters of this estimator.
transform(X)
Reduce X to the selected features.
Run score function on (X, y) and get the appropriate features.
The training input samples.
The target values (class labels in classification, real numbers in regression).
Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
Input samples.
Target values (None for unsupervised transformations).
Additional fit parameters.
Transformed array.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Get a mask, or integer index, of the features selected
If True, the return value will be an array of integers, rather than a boolean mask.
An index that selects the retained features from a feature vector. If indices is False, this is a boolean array of shape [# input features], in which an element is True iff its corresponding feature is selected for retention. If indices is True, this is an integer array of shape [# output features] whose values are indices into the input feature vector.
Reverse the transformation operation
The input samples.
X with columns of zeros inserted where features would have been removed by transform.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Reduce X to the selected features.
The input samples.
The input samples with only the selected features.


Select features according to a percentile of the highest scores.
Read more in the User Guide.
Function taking two arrays X and y, and returning a pair of arrays (scores, pvalues) or a single array with scores. Default is f_classif (see below “See Also”). The default function only works with classification tasks.
New in version 0.18.
Percent of features to keep.
Scores of features.
p-values of feature scores, None if score_func returned only scores.
See also
ANOVA F-value between label/feature for classification tasks.
Mutual information for a discrete target.
Chi-squared stats of non-negative features for classification tasks.
F-value between label/feature for regression tasks.
Mutual information for a continuous target.
Select features based on the k highest scores.
Select features based on a false positive rate test.
Select features based on an estimated false discovery rate.
Select features based on family-wise error rate.
Univariate feature selector with configurable mode.
Ties between features with equal scores will be broken in an unspecified way.
fit(X, y)
Run score function on (X, y) and get the appropriate features.
fit_transform(X[, y])
Fit to data, then transform it.
get_params([deep])
Get parameters for this estimator.
get_support([indices])
Get a mask, or integer index, of the features selected
inverse_transform(X)
Reverse the transformation operation
set_params(**params)
Set the parameters of this estimator.
transform(X)
Reduce X to the selected features.
Run score function on (X, y) and get the appropriate features.
The training input samples.
The target values (class labels in classification, real numbers in regression).
Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
Input samples.
Target values (None for unsupervised transformations).
Additional fit parameters.
Transformed array.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Get a mask, or integer index, of the features selected
If True, the return value will be an array of integers, rather than a boolean mask.
An index that selects the retained features from a feature vector. If indices is False, this is a boolean array of shape [# input features], in which an element is True iff its corresponding feature is selected for retention. If indices is True, this is an integer array of shape [# output features] whose values are indices into the input feature vector.
Reverse the transformation operation
The input samples.
X with columns of zeros inserted where features would have been removed by transform.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Reduce X to the selected features.
The input samples.
The input samples with only the selected features.
Feature agglomeration vs. univariate selection
SVM-Anova: SVM with univariate feature selection


Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.


Reduce X to the selected features.
The input samples.
The input samples with only the selected features.


Transformer that performs Sequential Feature Selection.
This Sequential Feature Selector adds (forward selection) or removes (backward selection) features to form a feature subset in a greedy fashion. At each stage, this estimator chooses the best feature to add or remove based on the cross-validation score of an estimator.
Read more in the User Guide.
New in version 0.24.
An unfitted estimator.
The number of features to select. If None, half of the features are selected. If integer, the parameter is the absolute number of features to select. If float between 0 and 1, it is the fraction of features to select.
Whether to perform forward selection or backward selection.
A single str (see The scoring parameter: defining model evaluation rules) or a callable (see Defining your scoring strategy from metric functions) to evaluate the predictions on the test set.
NOTE that when using custom scorers, each scorer should return a single value. Metric functions returning a list/array of values can be wrapped into multiple scorers that return one value each.
If None, the estimator’s score method is used.
Determines the cross-validation splitting strategy. Possible inputs for cv are:
For integer/None inputs, if the estimator is a classifier and y is either binary or multiclass, StratifiedKFold is used. In all other cases, KFold is used.
Refer User Guide for the various cross-validation strategies that can be used here.
Number of jobs to run in parallel. When evaluating a new feature to add or remove, the cross-validation procedure is parallel over the folds. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
The number of features that were selected.
The mask of selected features.
See also
Recursive feature elimination based on importance weights.
Recursive feature elimination based on importance weights, with automatic selection of the number of features.
Feature selection based on thresholds of importance weights.
fit(X, y)
Learn the features to select.
fit_transform(X[, y])
Fit to data, then transform it.
get_params([deep])
Get parameters for this estimator.
get_support([indices])
Get a mask, or integer index, of the features selected
inverse_transform(X)
Reverse the transformation operation
set_params(**params)
Set the parameters of this estimator.
transform(X)
Reduce X to the selected features.
Learn the features to select.
Training vectors.
Target values.
Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
Input samples.
Target values (None for unsupervised transformations).
Additional fit parameters.
Transformed array.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Get a mask, or integer index, of the features selected
If True, the return value will be an array of integers, rather than a boolean mask.
An index that selects the retained features from a feature vector. If indices is False, this is a boolean array of shape [# input features], in which an element is True iff its corresponding feature is selected for retention. If indices is True, this is an integer array of shape [# output features] whose values are indices into the input feature vector.
Reverse the transformation operation
The input samples.
X with columns of zeros inserted where features would have been removed by transform.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Reduce X to the selected features.
The input samples.
The input samples with only the selected features.


Transformer that performs Sequential Feature Selection.
This Sequential Feature Selector adds (forward selection) or removes (backward selection) features to form a feature subset in a greedy fashion. At each stage, this estimator chooses the best feature to add or remove based on the cross-validation score of an estimator.
Read more in the User Guide.
New in version 0.24.
An unfitted estimator.
The number of features to select. If None, half of the features are selected. If integer, the parameter is the absolute number of features to select. If float between 0 and 1, it is the fraction of features to select.
Whether to perform forward selection or backward selection.
A single str (see The scoring parameter: defining model evaluation rules) or a callable (see Defining your scoring strategy from metric functions) to evaluate the predictions on the test set.
NOTE that when using custom scorers, each scorer should return a single value. Metric functions returning a list/array of values can be wrapped into multiple scorers that return one value each.
If None, the estimator’s score method is used.
Determines the cross-validation splitting strategy. Possible inputs for cv are:
For integer/None inputs, if the estimator is a classifier and y is either binary or multiclass, StratifiedKFold is used. In all other cases, KFold is used.
Refer User Guide for the various cross-validation strategies that can be used here.
Number of jobs to run in parallel. When evaluating a new feature to add or remove, the cross-validation procedure is parallel over the folds. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
The number of features that were selected.
The mask of selected features.
See also
Recursive feature elimination based on importance weights.
Recursive feature elimination based on importance weights, with automatic selection of the number of features.
Feature selection based on thresholds of importance weights.
fit(X, y)
Learn the features to select.
fit_transform(X[, y])
Fit to data, then transform it.
get_params([deep])
Get parameters for this estimator.
get_support([indices])
Get a mask, or integer index, of the features selected
inverse_transform(X)
Reverse the transformation operation
set_params(**params)
Set the parameters of this estimator.
transform(X)
Reduce X to the selected features.
Learn the features to select.
Training vectors.
Target values.
Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
Input samples.
Target values (None for unsupervised transformations).
Additional fit parameters.
Transformed array.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Get a mask, or integer index, of the features selected
If True, the return value will be an array of integers, rather than a boolean mask.
An index that selects the retained features from a feature vector. If indices is False, this is a boolean array of shape [# input features], in which an element is True iff its corresponding feature is selected for retention. If indices is True, this is an integer array of shape [# output features] whose values are indices into the input feature vector.
Reverse the transformation operation
The input samples.
X with columns of zeros inserted where features would have been removed by transform.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Reduce X to the selected features.
The input samples.
The input samples with only the selected features.
Release Highlights for scikit-learn 0.24
Model-based and sequential feature selection


Learn the features to select.
Training vectors.
Target values.


Feature selector that removes all low-variance features.
This feature selection algorithm looks only at the features (X), not the desired outputs (y), and can thus be used for unsupervised learning.
Read more in the User Guide.
Features with a training-set variance lower than this threshold will be removed. The default is to keep all features with non-zero variance, i.e. remove the features that have the same value in all samples.
Variances of individual features.
Allows NaN in the input. Raises ValueError if no feature in X meets the variance threshold.
The following dataset has integer features, two of which are the same in every sample. These are removed with the default setting for threshold:
fit(X[, y])
Learn empirical variances from X.
fit_transform(X[, y])
Fit to data, then transform it.
get_params([deep])
Get parameters for this estimator.
get_support([indices])
Get a mask, or integer index, of the features selected
inverse_transform(X)
Reverse the transformation operation
set_params(**params)
Set the parameters of this estimator.
transform(X)
Reduce X to the selected features.
Learn empirical variances from X.
Sample vectors from which to compute variances.
Ignored. This parameter exists only for compatibility with sklearn.pipeline.Pipeline.
Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
Input samples.
Target values (None for unsupervised transformations).
Additional fit parameters.
Transformed array.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Get a mask, or integer index, of the features selected
If True, the return value will be an array of integers, rather than a boolean mask.
An index that selects the retained features from a feature vector. If indices is False, this is a boolean array of shape [# input features], in which an element is True iff its corresponding feature is selected for retention. If indices is True, this is an integer array of shape [# output features] whose values are indices into the input feature vector.
Reverse the transformation operation
The input samples.
X with columns of zeros inserted where features would have been removed by transform.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Reduce X to the selected features.
The input samples.
The input samples with only the selected features.


Learn empirical variances from X.
Sample vectors from which to compute variances.
Ignored. This parameter exists only for compatibility with sklearn.pipeline.Pipeline.


Gaussian process classification (GPC) based on Laplace approximation.
The implementation is based on Algorithm 3.1, 3.2, and 5.1 of Gaussian Processes for Machine Learning (GPML) by Rasmussen and Williams.
Internally, the Laplace approximation is used for approximating the non-Gaussian posterior by a Gaussian.
Currently, the implementation is restricted to using the logistic link function. For multi-class classification, several binary one-versus rest classifiers are fitted. Note that this class thus does not implement a true multi-class Laplace approximation.
Read more in the User Guide.
The kernel specifying the covariance function of the GP. If None is passed, the kernel “1.0 * RBF(1.0)” is used as default. Note that the kernel’s hyperparameters are optimized during fitting.
Can either be one of the internally supported optimizers for optimizing the kernel’s parameters, specified by a string, or an externally defined optimizer passed as a callable. If a callable is passed, it must have the signature:
Per default, the ‘L-BFGS-B’ algorithm from scipy.optimize.minimize is used. If None is passed, the kernel’s parameters are kept fixed. Available internal optimizers are:
The number of restarts of the optimizer for finding the kernel’s parameters which maximize the log-marginal likelihood. The first run of the optimizer is performed from the kernel’s initial parameters, the remaining ones (if any) from thetas sampled log-uniform randomly from the space of allowed theta-values. If greater than 0, all bounds must be finite. Note that n_restarts_optimizer=0 implies that one run is performed.
The maximum number of iterations in Newton’s method for approximating the posterior during predict. Smaller values will reduce computation time at the cost of worse results.
If warm-starts are enabled, the solution of the last Newton iteration on the Laplace approximation of the posterior mode is used as initialization for the next call of _posterior_mode(). This can speed up convergence when _posterior_mode is called several times on similar problems as in hyperparameter optimization. See the Glossary.
If True, a persistent copy of the training data is stored in the object. Otherwise, just a reference to the training data is stored, which might cause predictions to change if the data is modified externally.
Determines random number generation used to initialize the centers. Pass an int for reproducible results across multiple function calls. See :term: Glossary <random_state>.
Specifies how multi-class classification problems are handled. Supported are ‘one_vs_rest’ and ‘one_vs_one’. In ‘one_vs_rest’, one binary Gaussian process classifier is fitted for each class, which is trained to separate this class from the rest. In ‘one_vs_one’, one binary Gaussian process classifier is fitted for each pair of classes, which is trained to separate these two classes. The predictions of these binary predictors are combined into multi-class predictions. Note that ‘one_vs_one’ does not support predicting probability estimates.
The number of jobs to use for the computation: the specified multiclass problems are computed in parallel. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
The estimator instance that defines the likelihood function using the observed data.
The kernel used for prediction. In case of binary classification, the structure of the kernel is the same as the one passed as parameter but with optimized hyperparameters. In case of multi-class classification, a CompoundKernel is returned which consists of the different kernels used in the one-versus-rest classifiers.
The log-marginal-likelihood of self.kernel_.theta
Unique class labels.
The number of classes in the training data
New in version 0.18.
fit(X, y)
Fit Gaussian process classification model
get_params([deep])
Get parameters for this estimator.
log_marginal_likelihood([theta, …])
Returns log-marginal likelihood of theta for training data.
predict(X)
Perform classification on an array of test vectors X.
predict_proba(X)
Return probability estimates for the test vector X.
score(X, y[, sample_weight])
Return the mean accuracy on the given test data and labels.
set_params(**params)
Set the parameters of this estimator.
Fit Gaussian process classification model
Feature vectors or other representations of training data.
Target values, must be binary
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Returns log-marginal likelihood of theta for training data.
In the case of multi-class classification, the mean log-marginal likelihood of the one-versus-rest classifiers are returned.
Kernel hyperparameters for which the log-marginal likelihood is evaluated. In the case of multi-class classification, theta may be the hyperparameters of the compound kernel or of an individual kernel. In the latter case, all individual kernel get assigned the same theta values. If None, the precomputed log_marginal_likelihood of self.kernel_.theta is returned.
If True, the gradient of the log-marginal likelihood with respect to the kernel hyperparameters at position theta is returned additionally. Note that gradient computation is not supported for non-binary classification. If True, theta must not be None.
If True, the kernel attribute is copied. If False, the kernel attribute is modified, but may result in a performance improvement.
Log-marginal likelihood of theta for training data.
Gradient of the log-marginal likelihood with respect to the kernel hyperparameters at position theta. Only returned when eval_gradient is True.
Perform classification on an array of test vectors X.
Query points where the GP is evaluated for classification.
Predicted target values for X, values are from classes_
Return probability estimates for the test vector X.
Query points where the GP is evaluated for classification.
Returns the probability of the samples for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Test samples.
True labels for X.
Sample weights.
Mean accuracy of self.predict(X) wrt. y.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.


Gaussian process classification (GPC) based on Laplace approximation.
The implementation is based on Algorithm 3.1, 3.2, and 5.1 of Gaussian Processes for Machine Learning (GPML) by Rasmussen and Williams.
Internally, the Laplace approximation is used for approximating the non-Gaussian posterior by a Gaussian.
Currently, the implementation is restricted to using the logistic link function. For multi-class classification, several binary one-versus rest classifiers are fitted. Note that this class thus does not implement a true multi-class Laplace approximation.
Read more in the User Guide.
The kernel specifying the covariance function of the GP. If None is passed, the kernel “1.0 * RBF(1.0)” is used as default. Note that the kernel’s hyperparameters are optimized during fitting.
Can either be one of the internally supported optimizers for optimizing the kernel’s parameters, specified by a string, or an externally defined optimizer passed as a callable. If a callable is passed, it must have the signature:
Per default, the ‘L-BFGS-B’ algorithm from scipy.optimize.minimize is used. If None is passed, the kernel’s parameters are kept fixed. Available internal optimizers are:
The number of restarts of the optimizer for finding the kernel’s parameters which maximize the log-marginal likelihood. The first run of the optimizer is performed from the kernel’s initial parameters, the remaining ones (if any) from thetas sampled log-uniform randomly from the space of allowed theta-values. If greater than 0, all bounds must be finite. Note that n_restarts_optimizer=0 implies that one run is performed.
The maximum number of iterations in Newton’s method for approximating the posterior during predict. Smaller values will reduce computation time at the cost of worse results.
If warm-starts are enabled, the solution of the last Newton iteration on the Laplace approximation of the posterior mode is used as initialization for the next call of _posterior_mode(). This can speed up convergence when _posterior_mode is called several times on similar problems as in hyperparameter optimization. See the Glossary.
If True, a persistent copy of the training data is stored in the object. Otherwise, just a reference to the training data is stored, which might cause predictions to change if the data is modified externally.
Determines random number generation used to initialize the centers. Pass an int for reproducible results across multiple function calls. See :term: Glossary <random_state>.
Specifies how multi-class classification problems are handled. Supported are ‘one_vs_rest’ and ‘one_vs_one’. In ‘one_vs_rest’, one binary Gaussian process classifier is fitted for each class, which is trained to separate this class from the rest. In ‘one_vs_one’, one binary Gaussian process classifier is fitted for each pair of classes, which is trained to separate these two classes. The predictions of these binary predictors are combined into multi-class predictions. Note that ‘one_vs_one’ does not support predicting probability estimates.
The number of jobs to use for the computation: the specified multiclass problems are computed in parallel. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
The estimator instance that defines the likelihood function using the observed data.
The kernel used for prediction. In case of binary classification, the structure of the kernel is the same as the one passed as parameter but with optimized hyperparameters. In case of multi-class classification, a CompoundKernel is returned which consists of the different kernels used in the one-versus-rest classifiers.
The log-marginal-likelihood of self.kernel_.theta
Unique class labels.
The number of classes in the training data
New in version 0.18.
fit(X, y)
Fit Gaussian process classification model
get_params([deep])
Get parameters for this estimator.
log_marginal_likelihood([theta, …])
Returns log-marginal likelihood of theta for training data.
predict(X)
Perform classification on an array of test vectors X.
predict_proba(X)
Return probability estimates for the test vector X.
score(X, y[, sample_weight])
Return the mean accuracy on the given test data and labels.
set_params(**params)
Set the parameters of this estimator.
Fit Gaussian process classification model
Feature vectors or other representations of training data.
Target values, must be binary
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Returns log-marginal likelihood of theta for training data.
In the case of multi-class classification, the mean log-marginal likelihood of the one-versus-rest classifiers are returned.
Kernel hyperparameters for which the log-marginal likelihood is evaluated. In the case of multi-class classification, theta may be the hyperparameters of the compound kernel or of an individual kernel. In the latter case, all individual kernel get assigned the same theta values. If None, the precomputed log_marginal_likelihood of self.kernel_.theta is returned.
If True, the gradient of the log-marginal likelihood with respect to the kernel hyperparameters at position theta is returned additionally. Note that gradient computation is not supported for non-binary classification. If True, theta must not be None.
If True, the kernel attribute is copied. If False, the kernel attribute is modified, but may result in a performance improvement.
Log-marginal likelihood of theta for training data.
Gradient of the log-marginal likelihood with respect to the kernel hyperparameters at position theta. Only returned when eval_gradient is True.
Perform classification on an array of test vectors X.
Query points where the GP is evaluated for classification.
Predicted target values for X, values are from classes_
Return probability estimates for the test vector X.
Query points where the GP is evaluated for classification.
Returns the probability of the samples for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Test samples.
True labels for X.
Sample weights.
Mean accuracy of self.predict(X) wrt. y.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Plot classification probability
Classifier comparison
Illustration of Gaussian process classification (GPC) on the XOR dataset
Gaussian process classification (GPC) on iris dataset
Iso-probability lines for Gaussian Processes classification (GPC)
Probabilistic predictions with Gaussian process classification (GPC)
Gaussian processes on discrete data structures


Fit Gaussian process classification model
Feature vectors or other representations of training data.
Target values, must be binary


Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.


Returns log-marginal likelihood of theta for training data.
In the case of multi-class classification, the mean log-marginal likelihood of the one-versus-rest classifiers are returned.
Kernel hyperparameters for which the log-marginal likelihood is evaluated. In the case of multi-class classification, theta may be the hyperparameters of the compound kernel or of an individual kernel. In the latter case, all individual kernel get assigned the same theta values. If None, the precomputed log_marginal_likelihood of self.kernel_.theta is returned.
If True, the gradient of the log-marginal likelihood with respect to the kernel hyperparameters at position theta is returned additionally. Note that gradient computation is not supported for non-binary classification. If True, theta must not be None.
If True, the kernel attribute is copied. If False, the kernel attribute is modified, but may result in a performance improvement.
Log-marginal likelihood of theta for training data.
Gradient of the log-marginal likelihood with respect to the kernel hyperparameters at position theta. Only returned when eval_gradient is True.


Perform classification on an array of test vectors X.
Query points where the GP is evaluated for classification.
Predicted target values for X, values are from classes_


Return probability estimates for the test vector X.
Query points where the GP is evaluated for classification.
Returns the probability of the samples for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.


Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Test samples.
True labels for X.
Sample weights.
Mean accuracy of self.predict(X) wrt. y.


Gaussian process regression (GPR).
The implementation is based on Algorithm 2.1 of Gaussian Processes for Machine Learning (GPML) by Rasmussen and Williams.
In addition to standard scikit-learn estimator API, GaussianProcessRegressor:
Read more in the User Guide.
New in version 0.18.
The kernel specifying the covariance function of the GP. If None is passed, the kernel ConstantKernel(1.0, constant_value_bounds="fixed"
* RBF(1.0, length_scale_bounds="fixed") is used as default. Note that the kernel hyperparameters are optimized during fitting unless the bounds are marked as “fixed”.
Value added to the diagonal of the kernel matrix during fitting. This can prevent a potential numerical issue during fitting, by ensuring that the calculated values form a positive definite matrix. It can also be interpreted as the variance of additional Gaussian measurement noise on the training observations. Note that this is different from using a WhiteKernel. If an array is passed, it must have the same number of entries as the data used for fitting and is used as datapoint-dependent noise level. Allowing to specify the noise level directly as a parameter is mainly for convenience and for consistency with Ridge.
Can either be one of the internally supported optimizers for optimizing the kernel’s parameters, specified by a string, or an externally defined optimizer passed as a callable. If a callable is passed, it must have the signature:
Per default, the ‘L-BGFS-B’ algorithm from scipy.optimize.minimize is used. If None is passed, the kernel’s parameters are kept fixed. Available internal optimizers are:
The number of restarts of the optimizer for finding the kernel’s parameters which maximize the log-marginal likelihood. The first run of the optimizer is performed from the kernel’s initial parameters, the remaining ones (if any) from thetas sampled log-uniform randomly from the space of allowed theta-values. If greater than 0, all bounds must be finite. Note that n_restarts_optimizer == 0 implies that one run is performed.
Whether the target values y are normalized, the mean and variance of the target values are set equal to 0 and 1 respectively. This is recommended for cases where zero-mean, unit-variance priors are used. Note that, in this implementation, the normalisation is reversed before the GP predictions are reported.
Changed in version 0.23.
If True, a persistent copy of the training data is stored in the object. Otherwise, just a reference to the training data is stored, which might cause predictions to change if the data is modified externally.
Determines random number generation used to initialize the centers. Pass an int for reproducible results across multiple function calls. See :term: Glossary <random_state>.
Feature vectors or other representations of training data (also required for prediction).
Target values in training data (also required for prediction)
The kernel used for prediction. The structure of the kernel is the same as the one passed as parameter but with optimized hyperparameters
Lower-triangular Cholesky decomposition of the kernel in X_train_
Dual coefficients of training data points in kernel space
The log-marginal-likelihood of self.kernel_.theta
fit(X, y)
Fit Gaussian process regression model.
get_params([deep])
Get parameters for this estimator.
log_marginal_likelihood([theta, …])
Returns log-marginal likelihood of theta for training data.
predict(X[, return_std, return_cov])
Predict using the Gaussian process regression model
sample_y(X[, n_samples, random_state])
Draw samples from Gaussian process and evaluate at X.
score(X, y[, sample_weight])
Return the coefficient of determination \(R^2\) of the prediction.
set_params(**params)
Set the parameters of this estimator.
Fit Gaussian process regression model.
Feature vectors or other representations of training data.
Target values
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Returns log-marginal likelihood of theta for training data.
Kernel hyperparameters for which the log-marginal likelihood is evaluated. If None, the precomputed log_marginal_likelihood of self.kernel_.theta is returned.
If True, the gradient of the log-marginal likelihood with respect to the kernel hyperparameters at position theta is returned additionally. If True, theta must not be None.
If True, the kernel attribute is copied. If False, the kernel attribute is modified, but may result in a performance improvement.
Log-marginal likelihood of theta for training data.
Gradient of the log-marginal likelihood with respect to the kernel hyperparameters at position theta. Only returned when eval_gradient is True.
Predict using the Gaussian process regression model
We can also predict based on an unfitted model by using the GP prior. In addition to the mean of the predictive distribution, also its standard deviation (return_std=True) or covariance (return_cov=True). Note that at most one of the two can be requested.
Query points where the GP is evaluated.
If True, the standard-deviation of the predictive distribution at the query points is returned along with the mean.
If True, the covariance of the joint predictive distribution at the query points is returned along with the mean.
Mean of predictive distribution a query points.
Standard deviation of predictive distribution at query points. Only returned when return_std is True.
Covariance of joint predictive distribution a query points. Only returned when return_cov is True.
Draw samples from Gaussian process and evaluate at X.
Query points where the GP is evaluated.
The number of samples drawn from the Gaussian process
Determines random number generation to randomly draw samples. Pass an int for reproducible results across multiple function calls. See :term: Glossary <random_state>.
Values of n_samples samples drawn from Gaussian process and evaluated at query points.
Return the coefficient of determination \(R^2\) of the prediction.
The coefficient \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)
** 2).sum() and \(v\) is the total sum of squares ((y_true -
y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.
Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator.
True values for X.
Sample weights.
\(R^2\) of self.predict(X) wrt. y.
The \(R^2\) score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of r2_score. This influences the score method of all the multioutput regressors (except for MultiOutputRegressor).
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.


Gaussian process regression (GPR).
The implementation is based on Algorithm 2.1 of Gaussian Processes for Machine Learning (GPML) by Rasmussen and Williams.
In addition to standard scikit-learn estimator API, GaussianProcessRegressor:
Read more in the User Guide.
New in version 0.18.
The kernel specifying the covariance function of the GP. If None is passed, the kernel ConstantKernel(1.0, constant_value_bounds="fixed"
* RBF(1.0, length_scale_bounds="fixed") is used as default. Note that the kernel hyperparameters are optimized during fitting unless the bounds are marked as “fixed”.
Value added to the diagonal of the kernel matrix during fitting. This can prevent a potential numerical issue during fitting, by ensuring that the calculated values form a positive definite matrix. It can also be interpreted as the variance of additional Gaussian measurement noise on the training observations. Note that this is different from using a WhiteKernel. If an array is passed, it must have the same number of entries as the data used for fitting and is used as datapoint-dependent noise level. Allowing to specify the noise level directly as a parameter is mainly for convenience and for consistency with Ridge.
Can either be one of the internally supported optimizers for optimizing the kernel’s parameters, specified by a string, or an externally defined optimizer passed as a callable. If a callable is passed, it must have the signature:
Per default, the ‘L-BGFS-B’ algorithm from scipy.optimize.minimize is used. If None is passed, the kernel’s parameters are kept fixed. Available internal optimizers are:
The number of restarts of the optimizer for finding the kernel’s parameters which maximize the log-marginal likelihood. The first run of the optimizer is performed from the kernel’s initial parameters, the remaining ones (if any) from thetas sampled log-uniform randomly from the space of allowed theta-values. If greater than 0, all bounds must be finite. Note that n_restarts_optimizer == 0 implies that one run is performed.
Whether the target values y are normalized, the mean and variance of the target values are set equal to 0 and 1 respectively. This is recommended for cases where zero-mean, unit-variance priors are used. Note that, in this implementation, the normalisation is reversed before the GP predictions are reported.
Changed in version 0.23.
If True, a persistent copy of the training data is stored in the object. Otherwise, just a reference to the training data is stored, which might cause predictions to change if the data is modified externally.
Determines random number generation used to initialize the centers. Pass an int for reproducible results across multiple function calls. See :term: Glossary <random_state>.
Feature vectors or other representations of training data (also required for prediction).
Target values in training data (also required for prediction)
The kernel used for prediction. The structure of the kernel is the same as the one passed as parameter but with optimized hyperparameters
Lower-triangular Cholesky decomposition of the kernel in X_train_
Dual coefficients of training data points in kernel space
The log-marginal-likelihood of self.kernel_.theta
fit(X, y)
Fit Gaussian process regression model.
get_params([deep])
Get parameters for this estimator.
log_marginal_likelihood([theta, …])
Returns log-marginal likelihood of theta for training data.
predict(X[, return_std, return_cov])
Predict using the Gaussian process regression model
sample_y(X[, n_samples, random_state])
Draw samples from Gaussian process and evaluate at X.
score(X, y[, sample_weight])
Return the coefficient of determination \(R^2\) of the prediction.
set_params(**params)
Set the parameters of this estimator.
Fit Gaussian process regression model.
Feature vectors or other representations of training data.
Target values
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Returns log-marginal likelihood of theta for training data.
Kernel hyperparameters for which the log-marginal likelihood is evaluated. If None, the precomputed log_marginal_likelihood of self.kernel_.theta is returned.
If True, the gradient of the log-marginal likelihood with respect to the kernel hyperparameters at position theta is returned additionally. If True, theta must not be None.
If True, the kernel attribute is copied. If False, the kernel attribute is modified, but may result in a performance improvement.
Log-marginal likelihood of theta for training data.
Gradient of the log-marginal likelihood with respect to the kernel hyperparameters at position theta. Only returned when eval_gradient is True.
Predict using the Gaussian process regression model
We can also predict based on an unfitted model by using the GP prior. In addition to the mean of the predictive distribution, also its standard deviation (return_std=True) or covariance (return_cov=True). Note that at most one of the two can be requested.
Query points where the GP is evaluated.
If True, the standard-deviation of the predictive distribution at the query points is returned along with the mean.
If True, the covariance of the joint predictive distribution at the query points is returned along with the mean.
Mean of predictive distribution a query points.
Standard deviation of predictive distribution at query points. Only returned when return_std is True.
Covariance of joint predictive distribution a query points. Only returned when return_cov is True.
Draw samples from Gaussian process and evaluate at X.
Query points where the GP is evaluated.
The number of samples drawn from the Gaussian process
Determines random number generation to randomly draw samples. Pass an int for reproducible results across multiple function calls. See :term: Glossary <random_state>.
Values of n_samples samples drawn from Gaussian process and evaluated at query points.
Return the coefficient of determination \(R^2\) of the prediction.
The coefficient \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)
** 2).sum() and \(v\) is the total sum of squares ((y_true -
y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.
Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator.
True values for X.
Sample weights.
\(R^2\) of self.predict(X) wrt. y.
The \(R^2\) score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of r2_score. This influences the score method of all the multioutput regressors (except for MultiOutputRegressor).
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Comparison of kernel ridge and Gaussian process regression
Illustration of prior and posterior Gaussian process for different kernels
Gaussian process regression (GPR) with noise-level estimation
Gaussian Processes regression: basic introductory example
Gaussian process regression (GPR) on Mauna Loa CO2 data.
Gaussian processes on discrete data structures


Fit Gaussian process regression model.
Feature vectors or other representations of training data.
Target values


Returns log-marginal likelihood of theta for training data.
Kernel hyperparameters for which the log-marginal likelihood is evaluated. If None, the precomputed log_marginal_likelihood of self.kernel_.theta is returned.
If True, the gradient of the log-marginal likelihood with respect to the kernel hyperparameters at position theta is returned additionally. If True, theta must not be None.
If True, the kernel attribute is copied. If False, the kernel attribute is modified, but may result in a performance improvement.
Log-marginal likelihood of theta for training data.
Gradient of the log-marginal likelihood with respect to the kernel hyperparameters at position theta. Only returned when eval_gradient is True.


Predict using the Gaussian process regression model
We can also predict based on an unfitted model by using the GP prior. In addition to the mean of the predictive distribution, also its standard deviation (return_std=True) or covariance (return_cov=True). Note that at most one of the two can be requested.
Query points where the GP is evaluated.
If True, the standard-deviation of the predictive distribution at the query points is returned along with the mean.
If True, the covariance of the joint predictive distribution at the query points is returned along with the mean.
Mean of predictive distribution a query points.
Standard deviation of predictive distribution at query points. Only returned when return_std is True.
Covariance of joint predictive distribution a query points. Only returned when return_cov is True.


Draw samples from Gaussian process and evaluate at X.
Query points where the GP is evaluated.
The number of samples drawn from the Gaussian process
Determines random number generation to randomly draw samples. Pass an int for reproducible results across multiple function calls. See :term: Glossary <random_state>.
Values of n_samples samples drawn from Gaussian process and evaluated at query points.


Return the coefficient of determination \(R^2\) of the prediction.
The coefficient \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)
** 2).sum() and \(v\) is the total sum of squares ((y_true -
y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.
Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator.
True values for X.
Sample weights.
\(R^2\) of self.predict(X) wrt. y.
The \(R^2\) score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of r2_score. This influences the score method of all the multioutput regressors (except for MultiOutputRegressor).


Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.