sklearn.feature_selection.GenericUnivariateSelect
class sklearn.feature_selection.GenericUnivariateSelect(score_func=<function f_classif>, *, mode='percentile', param=1e-05) [source]

Univariate feature selector with configurable strategy. Read more in the User Guide.  Parameters

score_funccallable, default=f_classif

Function taking two arrays X and y, and returning a pair of arrays (scores, pvalues). For modes ‘percentile’ or ‘kbest’ it can return a single array scores.
mode{‘percentile’, ‘k_best’, ‘fpr’, ‘fdr’, ‘fwe’}, default=’percentile’

Feature selection mode.
paramfloat or int depending on the feature selection mode, default=1e-5

Parameter of the corresponding mode.    Attributes

scores_array-like of shape (n_features,)

Scores of features.
pvalues_array-like of shape (n_features,)

p-values of feature scores, None if score_func returned scores only.      See also
f_classif

ANOVA F-value between label/feature for classification tasks.
mutual_info_classif

Mutual information for a discrete target.
chi2

Chi-squared stats of non-negative features for classification tasks.
f_regression

F-value between label/feature for regression tasks.
mutual_info_regression

Mutual information for a continuous target.
SelectPercentile

Select features based on percentile of the highest scores.
SelectKBest

Select features based on the k highest scores.
SelectFpr

Select features based on a false positive rate test.
SelectFdr

Select features based on an estimated false discovery rate.
SelectFwe

Select features based on family-wise error rate.    Examples >>> from sklearn.datasets import load_breast_cancer
>>> from sklearn.feature_selection import GenericUnivariateSelect, chi2
>>> X, y = load_breast_cancer(return_X_y=True)
>>> X.shape
(569, 30)
>>> transformer = GenericUnivariateSelect(chi2, mode='k_best', param=20)
>>> X_new = transformer.fit_transform(X, y)
>>> X_new.shape
(569, 20)
 Methods
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.
fit(X, y) [source]

Run score function on (X, y) and get the appropriate features.  Parameters

Xarray-like of shape (n_samples, n_features)

The training input samples.
yarray-like of shape (n_samples,)

The target values (class labels in classification, real numbers in regression).    Returns

selfobject

fit_transform(X, y=None, **fit_params) [source]

Fit to data, then transform it. Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.  Parameters

Xarray-like of shape (n_samples, n_features)

Input samples.
yarray-like of shape (n_samples,) or (n_samples, n_outputs), default=None

Target values (None for unsupervised transformations).
**fit_paramsdict

Additional fit parameters.    Returns

X_newndarray array of shape (n_samples, n_features_new)

Transformed array.

get_params(deep=True) [source]

Get parameters for this estimator.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.

get_support(indices=False) [source]

Get a mask, or integer index, of the features selected  Parameters

indicesbool, default=False

If True, the return value will be an array of integers, rather than a boolean mask.    Returns

supportarray

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.

inverse_transform(X) [source]

Reverse the transformation operation  Parameters

Xarray of shape [n_samples, n_selected_features]

The input samples.    Returns

X_rarray of shape [n_samples, n_original_features]

X with columns of zeros inserted where features would have been removed by transform.

set_params(**params) [source]

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.  Parameters

**paramsdict

Estimator parameters.    Returns

selfestimator instance

Estimator instance.

transform(X) [source]

Reduce X to the selected features.  Parameters

Xarray of shape [n_samples, n_features]

The input samples.    Returns

X_rarray of shape [n_samples, n_selected_features]

The input samples with only the selected features.


fit(X, y) [source]

Run score function on (X, y) and get the appropriate features.  Parameters

Xarray-like of shape (n_samples, n_features)

The training input samples.
yarray-like of shape (n_samples,)

The target values (class labels in classification, real numbers in regression).    Returns

selfobject


fit_transform(X, y=None, **fit_params) [source]

Fit to data, then transform it. Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.  Parameters

Xarray-like of shape (n_samples, n_features)

Input samples.
yarray-like of shape (n_samples,) or (n_samples, n_outputs), default=None

Target values (None for unsupervised transformations).
**fit_paramsdict

Additional fit parameters.    Returns

X_newndarray array of shape (n_samples, n_features_new)

Transformed array.


get_params(deep=True) [source]

Get parameters for this estimator.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.


get_support(indices=False) [source]

Get a mask, or integer index, of the features selected  Parameters

indicesbool, default=False

If True, the return value will be an array of integers, rather than a boolean mask.    Returns

supportarray

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.


inverse_transform(X) [source]

Reverse the transformation operation  Parameters

Xarray of shape [n_samples, n_selected_features]

The input samples.    Returns

X_rarray of shape [n_samples, n_original_features]

X with columns of zeros inserted where features would have been removed by transform.


set_params(**params) [source]

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.  Parameters

**paramsdict

Estimator parameters.    Returns

selfestimator instance

Estimator instance.


transform(X) [source]

Reduce X to the selected features.  Parameters

Xarray of shape [n_samples, n_features]

The input samples.    Returns

X_rarray of shape [n_samples, n_selected_features]

The input samples with only the selected features.


sklearn.feature_selection.mutual_info_classif(X, y, *, discrete_features='auto', n_neighbors=3, copy=True, random_state=None) [source]

Estimate mutual information for a discrete target variable. Mutual information (MI) [1] between two random variables is a non-negative value, which measures the dependency between the variables. It is equal to zero if and only if two random variables are independent, and higher values mean higher dependency. The function relies on nonparametric methods based on entropy estimation from k-nearest neighbors distances as described in [2] and [3]. Both methods are based on the idea originally proposed in [4]. It can be used for univariate features selection, read more in the User Guide.  Parameters

Xarray-like or sparse matrix, shape (n_samples, n_features)

Feature matrix.
yarray-like of shape (n_samples,)

Target vector.
discrete_features{‘auto’, bool, array-like}, default=’auto’

If bool, then determines whether to consider all features discrete or continuous. If array, then it should be either a boolean mask with shape (n_features,) or array with indices of discrete features. If ‘auto’, it is assigned to False for dense X and to True for sparse X.
n_neighborsint, default=3

Number of neighbors to use for MI estimation for continuous variables, see [2] and [3]. Higher values reduce variance of the estimation, but could introduce a bias.
copybool, default=True

Whether to make a copy of the given data. If set to False, the initial data will be overwritten.
random_stateint, RandomState instance or None, default=None

Determines random number generation for adding small noise to continuous variables in order to remove repeated values. Pass an int for reproducible results across multiple function calls. See Glossary.    Returns

mindarray, shape (n_features,)

Estimated mutual information between each feature and the target.     Notes  The term “discrete features” is used instead of naming them “categorical”, because it describes the essence more accurately. For example, pixel intensities of an image are discrete features (but hardly categorical) and you will get better results if mark them as such. Also note, that treating a continuous variable as discrete and vice versa will usually give incorrect results, so be attentive about that. True mutual information can’t be negative. If its estimate turns out to be negative, it is replaced by zero.  References
1
Mutual Information on Wikipedia.
2(1,2)
A. Kraskov, H. Stogbauer and P. Grassberger, “Estimating mutual information”. Phys. Rev. E 69, 2004.
3(1,2)
B. C. Ross “Mutual Information between Discrete and Continuous Data Sets”. PLoS ONE 9(2), 2014.
4
L. F. Kozachenko, N. N. Leonenko, “Sample Estimate of the Entropy of a Random Vector:, Probl. Peredachi Inf., 23:2 (1987), 9-16


sklearn.feature_selection.mutual_info_regression(X, y, *, discrete_features='auto', n_neighbors=3, copy=True, random_state=None) [source]

Estimate mutual information for a continuous target variable. Mutual information (MI) [1] between two random variables is a non-negative value, which measures the dependency between the variables. It is equal to zero if and only if two random variables are independent, and higher values mean higher dependency. The function relies on nonparametric methods based on entropy estimation from k-nearest neighbors distances as described in [2] and [3]. Both methods are based on the idea originally proposed in [4]. It can be used for univariate features selection, read more in the User Guide.  Parameters

Xarray-like or sparse matrix, shape (n_samples, n_features)

Feature matrix.
yarray-like of shape (n_samples,)

Target vector.
discrete_features{‘auto’, bool, array-like}, default=’auto’

If bool, then determines whether to consider all features discrete or continuous. If array, then it should be either a boolean mask with shape (n_features,) or array with indices of discrete features. If ‘auto’, it is assigned to False for dense X and to True for sparse X.
n_neighborsint, default=3

Number of neighbors to use for MI estimation for continuous variables, see [2] and [3]. Higher values reduce variance of the estimation, but could introduce a bias.
copybool, default=True

Whether to make a copy of the given data. If set to False, the initial data will be overwritten.
random_stateint, RandomState instance or None, default=None

Determines random number generation for adding small noise to continuous variables in order to remove repeated values. Pass an int for reproducible results across multiple function calls. See Glossary.    Returns

mindarray, shape (n_features,)

Estimated mutual information between each feature and the target.     Notes  The term “discrete features” is used instead of naming them “categorical”, because it describes the essence more accurately. For example, pixel intensities of an image are discrete features (but hardly categorical) and you will get better results if mark them as such. Also note, that treating a continuous variable as discrete and vice versa will usually give incorrect results, so be attentive about that. True mutual information can’t be negative. If its estimate turns out to be negative, it is replaced by zero.  References
1
Mutual Information on Wikipedia.
2(1,2)
A. Kraskov, H. Stogbauer and P. Grassberger, “Estimating mutual information”. Phys. Rev. E 69, 2004.
3(1,2)
B. C. Ross “Mutual Information between Discrete and Continuous Data Sets”. PLoS ONE 9(2), 2014.
4
L. F. Kozachenko, N. N. Leonenko, “Sample Estimate of the Entropy of a Random Vector”, Probl. Peredachi Inf., 23:2 (1987), 9-16


class sklearn.feature_selection.RFE(estimator, *, n_features_to_select=None, step=1, verbose=0, importance_getter='auto') [source]

Feature ranking with recursive feature elimination. Given an external estimator that assigns weights to features (e.g., the coefficients of a linear model), the goal of recursive feature elimination (RFE) is to select features by recursively considering smaller and smaller sets of features. First, the estimator is trained on the initial set of features and the importance of each feature is obtained either through any specific attribute or callable. Then, the least important features are pruned from current set of features. That procedure is recursively repeated on the pruned set until the desired number of features to select is eventually reached. Read more in the User Guide.  Parameters

estimatorEstimator instance

A supervised learning estimator with a fit method that provides information about feature importance (e.g. coef_, feature_importances_).
n_features_to_selectint or float, default=None

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.  Changed in version 0.24: Added float values for fractions.
stepint or float, default=1

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.
verboseint, default=0

Controls verbosity of output.
importance_getterstr or callable, default=’auto’

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 (implemented with attrgetter). For example, give regressor_.coef_ in case of TransformedTargetRegressor or named_steps.clf.feature_importances_ in case of class:~sklearn.pipeline.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.     Attributes

estimator_Estimator instance

The fitted estimator used to select features.
n_features_int

The number of selected features.
ranking_ndarray of shape (n_features,)

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.
support_ndarray of shape (n_features,)

The mask of selected features.      See also
RFECV

Recursive feature elimination with built-in cross-validated selection of the best number of features.
SelectFromModel

Feature selection based on thresholds of importance weights.
SequentialFeatureSelector

Sequential cross-validation based feature selection. Does not rely on importance weights.    Notes Allows NaN/Inf in the input if the underlying estimator does as well. References
1
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.   Examples The following example shows how to retrieve the 5 most informative features in the Friedman #1 dataset. >>> from sklearn.datasets import make_friedman1
>>> from sklearn.feature_selection import RFE
>>> from sklearn.svm import SVR
>>> X, y = make_friedman1(n_samples=50, n_features=10, random_state=0)
>>> estimator = SVR(kernel="linear")
>>> selector = RFE(estimator, n_features_to_select=5, step=1)
>>> selector = selector.fit(X, y)
>>> selector.support_
array([ True,  True,  True,  True,  True, False, False, False, False,
       False])
>>> selector.ranking_
array([1, 1, 1, 1, 1, 6, 4, 3, 2, 5])
 Methods
decision_function(X) Compute the decision function of X.
fit(X, y) Fit the RFE model and then the underlying estimator on the 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.
decision_function(X) [source]

Compute the decision function of X.  Parameters

X{array-like or sparse matrix} of shape (n_samples, n_features)

The input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr_matrix.    Returns

scorearray, shape = [n_samples, n_classes] or [n_samples]

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].

fit(X, y) [source]

 Fit the RFE model and then the underlying estimator on the selected

features.    Parameters

X{array-like, sparse matrix} of shape (n_samples, n_features)

The training input samples.
yarray-like of shape (n_samples,)

The target values.

fit_transform(X, y=None, **fit_params) [source]

Fit to data, then transform it. Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.  Parameters

Xarray-like of shape (n_samples, n_features)

Input samples.
yarray-like of shape (n_samples,) or (n_samples, n_outputs), default=None

Target values (None for unsupervised transformations).
**fit_paramsdict

Additional fit parameters.    Returns

X_newndarray array of shape (n_samples, n_features_new)

Transformed array.

get_params(deep=True) [source]

Get parameters for this estimator.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.

get_support(indices=False) [source]

Get a mask, or integer index, of the features selected  Parameters

indicesbool, default=False

If True, the return value will be an array of integers, rather than a boolean mask.    Returns

supportarray

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.

inverse_transform(X) [source]

Reverse the transformation operation  Parameters

Xarray of shape [n_samples, n_selected_features]

The input samples.    Returns

X_rarray of shape [n_samples, n_original_features]

X with columns of zeros inserted where features would have been removed by transform.

predict(X) [source]

 Reduce X to the selected features and then predict using the

underlying estimator.    Parameters

Xarray of shape [n_samples, n_features]

The input samples.    Returns

yarray of shape [n_samples]

The predicted target values.

predict_log_proba(X) [source]

Predict class log-probabilities for X.  Parameters

Xarray of shape [n_samples, n_features]

The input samples.    Returns

parray of shape (n_samples, n_classes)

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

predict_proba(X) [source]

Predict class probabilities for X.  Parameters

X{array-like or sparse matrix} of shape (n_samples, n_features)

The input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr_matrix.    Returns

parray of shape (n_samples, n_classes)

The class probabilities of the input samples. The order of the classes corresponds to that in the attribute classes_.

score(X, y) [source]

 Reduce X to the selected features and then return the score of the

underlying estimator.    Parameters

Xarray of shape [n_samples, n_features]

The input samples.
yarray of shape [n_samples]

The target values.

set_params(**params) [source]

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.  Parameters

**paramsdict

Estimator parameters.    Returns

selfestimator instance

Estimator instance.

transform(X) [source]

Reduce X to the selected features.  Parameters

Xarray of shape [n_samples, n_features]

The input samples.    Returns

X_rarray of shape [n_samples, n_selected_features]

The input samples with only the selected features.


sklearn.feature_selection.RFE
class sklearn.feature_selection.RFE(estimator, *, n_features_to_select=None, step=1, verbose=0, importance_getter='auto') [source]

Feature ranking with recursive feature elimination. Given an external estimator that assigns weights to features (e.g., the coefficients of a linear model), the goal of recursive feature elimination (RFE) is to select features by recursively considering smaller and smaller sets of features. First, the estimator is trained on the initial set of features and the importance of each feature is obtained either through any specific attribute or callable. Then, the least important features are pruned from current set of features. That procedure is recursively repeated on the pruned set until the desired number of features to select is eventually reached. Read more in the User Guide.  Parameters

estimatorEstimator instance

A supervised learning estimator with a fit method that provides information about feature importance (e.g. coef_, feature_importances_).
n_features_to_selectint or float, default=None

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.  Changed in version 0.24: Added float values for fractions.
stepint or float, default=1

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.
verboseint, default=0

Controls verbosity of output.
importance_getterstr or callable, default=’auto’

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 (implemented with attrgetter). For example, give regressor_.coef_ in case of TransformedTargetRegressor or named_steps.clf.feature_importances_ in case of class:~sklearn.pipeline.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.     Attributes

estimator_Estimator instance

The fitted estimator used to select features.
n_features_int

The number of selected features.
ranking_ndarray of shape (n_features,)

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.
support_ndarray of shape (n_features,)

The mask of selected features.      See also
RFECV

Recursive feature elimination with built-in cross-validated selection of the best number of features.
SelectFromModel

Feature selection based on thresholds of importance weights.
SequentialFeatureSelector

Sequential cross-validation based feature selection. Does not rely on importance weights.    Notes Allows NaN/Inf in the input if the underlying estimator does as well. References
1
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.   Examples The following example shows how to retrieve the 5 most informative features in the Friedman #1 dataset. >>> from sklearn.datasets import make_friedman1
>>> from sklearn.feature_selection import RFE
>>> from sklearn.svm import SVR
>>> X, y = make_friedman1(n_samples=50, n_features=10, random_state=0)
>>> estimator = SVR(kernel="linear")
>>> selector = RFE(estimator, n_features_to_select=5, step=1)
>>> selector = selector.fit(X, y)
>>> selector.support_
array([ True,  True,  True,  True,  True, False, False, False, False,
       False])
>>> selector.ranking_
array([1, 1, 1, 1, 1, 6, 4, 3, 2, 5])
 Methods
decision_function(X) Compute the decision function of X.
fit(X, y) Fit the RFE model and then the underlying estimator on the 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.
decision_function(X) [source]

Compute the decision function of X.  Parameters

X{array-like or sparse matrix} of shape (n_samples, n_features)

The input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr_matrix.    Returns

scorearray, shape = [n_samples, n_classes] or [n_samples]

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].

fit(X, y) [source]

 Fit the RFE model and then the underlying estimator on the selected

features.    Parameters

X{array-like, sparse matrix} of shape (n_samples, n_features)

The training input samples.
yarray-like of shape (n_samples,)

The target values.

fit_transform(X, y=None, **fit_params) [source]

Fit to data, then transform it. Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.  Parameters

Xarray-like of shape (n_samples, n_features)

Input samples.
yarray-like of shape (n_samples,) or (n_samples, n_outputs), default=None

Target values (None for unsupervised transformations).
**fit_paramsdict

Additional fit parameters.    Returns

X_newndarray array of shape (n_samples, n_features_new)

Transformed array.

get_params(deep=True) [source]

Get parameters for this estimator.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.

get_support(indices=False) [source]

Get a mask, or integer index, of the features selected  Parameters

indicesbool, default=False

If True, the return value will be an array of integers, rather than a boolean mask.    Returns

supportarray

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.

inverse_transform(X) [source]

Reverse the transformation operation  Parameters

Xarray of shape [n_samples, n_selected_features]

The input samples.    Returns

X_rarray of shape [n_samples, n_original_features]

X with columns of zeros inserted where features would have been removed by transform.

predict(X) [source]

 Reduce X to the selected features and then predict using the

underlying estimator.    Parameters

Xarray of shape [n_samples, n_features]

The input samples.    Returns

yarray of shape [n_samples]

The predicted target values.

predict_log_proba(X) [source]

Predict class log-probabilities for X.  Parameters

Xarray of shape [n_samples, n_features]

The input samples.    Returns

parray of shape (n_samples, n_classes)

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

predict_proba(X) [source]

Predict class probabilities for X.  Parameters

X{array-like or sparse matrix} of shape (n_samples, n_features)

The input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr_matrix.    Returns

parray of shape (n_samples, n_classes)

The class probabilities of the input samples. The order of the classes corresponds to that in the attribute classes_.

score(X, y) [source]

 Reduce X to the selected features and then return the score of the

underlying estimator.    Parameters

Xarray of shape [n_samples, n_features]

The input samples.
yarray of shape [n_samples]

The target values.

set_params(**params) [source]

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.  Parameters

**paramsdict

Estimator parameters.    Returns

selfestimator instance

Estimator instance.

transform(X) [source]

Reduce X to the selected features.  Parameters

Xarray of shape [n_samples, n_features]

The input samples.    Returns

X_rarray of shape [n_samples, n_selected_features]

The input samples with only the selected features.

 Examples using sklearn.feature_selection.RFE

  Recursive feature elimination


decision_function(X) [source]

Compute the decision function of X.  Parameters

X{array-like or sparse matrix} of shape (n_samples, n_features)

The input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr_matrix.    Returns

scorearray, shape = [n_samples, n_classes] or [n_samples]

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].


fit(X, y) [source]

 Fit the RFE model and then the underlying estimator on the selected

features.    Parameters

X{array-like, sparse matrix} of shape (n_samples, n_features)

The training input samples.
yarray-like of shape (n_samples,)

The target values.


predict(X) [source]

 Reduce X to the selected features and then predict using the

underlying estimator.    Parameters

Xarray of shape [n_samples, n_features]

The input samples.    Returns

yarray of shape [n_samples]

The predicted target values.


predict_log_proba(X) [source]

Predict class log-probabilities for X.  Parameters

Xarray of shape [n_samples, n_features]

The input samples.    Returns

parray of shape (n_samples, n_classes)

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


predict_proba(X) [source]

Predict class probabilities for X.  Parameters

X{array-like or sparse matrix} of shape (n_samples, n_features)

The input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr_matrix.    Returns

parray of shape (n_samples, n_classes)

The class probabilities of the input samples. The order of the classes corresponds to that in the attribute classes_.


score(X, y) [source]

 Reduce X to the selected features and then return the score of the

underlying estimator.    Parameters

Xarray of shape [n_samples, n_features]

The input samples.
yarray of shape [n_samples]

The target values.


class sklearn.feature_selection.RFECV(estimator, *, step=1, min_features_to_select=1, cv=None, scoring=None, verbose=0, n_jobs=None, importance_getter='auto') [source]

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.  Parameters

estimatorEstimator instance

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.
stepint or float, default=1

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.
min_features_to_selectint, default=1

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.
cvint, cross-validation generator or an iterable, default=None

Determines the cross-validation splitting strategy. Possible inputs for cv are:  None, to use the default 5-fold cross-validation, integer, to specify the number of folds.
CV splitter, An iterable yielding (train, test) splits as arrays of indices.  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.
scoringstring, callable or None, default=None

A string (see model evaluation documentation) or a scorer callable object / function with signature scorer(estimator, X, y).
verboseint, default=0

Controls verbosity of output.
n_jobsint or None, default=None

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.
importance_getterstr or callable, default=’auto’

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.     Attributes

estimator_Estimator instance

The fitted estimator used to select features.
grid_scores_ndarray of shape (n_subsets_of_features,)

The cross-validation scores such that grid_scores_[i] corresponds to the CV score of the i-th subset of features.
n_features_int

The number of selected features with cross-validation.
ranking_narray of shape (n_features,)

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.
support_ndarray of shape (n_features,)

The mask of selected features.      See also
RFE

Recursive feature elimination.    Notes 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. References
1
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.   Examples The following example shows how to retrieve the a-priori not known 5 informative features in the Friedman #1 dataset. >>> from sklearn.datasets import make_friedman1
>>> from sklearn.feature_selection import RFECV
>>> from sklearn.svm import SVR
>>> X, y = make_friedman1(n_samples=50, n_features=10, random_state=0)
>>> estimator = SVR(kernel="linear")
>>> selector = RFECV(estimator, step=1, cv=5)
>>> selector = selector.fit(X, y)
>>> selector.support_
array([ True,  True,  True,  True,  True, False, False, False, False,
       False])
>>> selector.ranking_
array([1, 1, 1, 1, 1, 6, 4, 3, 2, 5])
 Methods
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.
decision_function(X) [source]

Compute the decision function of X.  Parameters

X{array-like or sparse matrix} of shape (n_samples, n_features)

The input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr_matrix.    Returns

scorearray, shape = [n_samples, n_classes] or [n_samples]

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].

fit(X, y, groups=None) [source]

 Fit the RFE model and automatically tune the number of selected

features.    Parameters

X{array-like, sparse matrix} of shape (n_samples, n_features)

Training vector, where n_samples is the number of samples and n_features is the total number of features.
yarray-like of shape (n_samples,)

Target values (integers for classification, real numbers for regression).
groupsarray-like of shape (n_samples,) or None, default=None

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_transform(X, y=None, **fit_params) [source]

Fit to data, then transform it. Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.  Parameters

Xarray-like of shape (n_samples, n_features)

Input samples.
yarray-like of shape (n_samples,) or (n_samples, n_outputs), default=None

Target values (None for unsupervised transformations).
**fit_paramsdict

Additional fit parameters.    Returns

X_newndarray array of shape (n_samples, n_features_new)

Transformed array.

get_params(deep=True) [source]

Get parameters for this estimator.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.

get_support(indices=False) [source]

Get a mask, or integer index, of the features selected  Parameters

indicesbool, default=False

If True, the return value will be an array of integers, rather than a boolean mask.    Returns

supportarray

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.

inverse_transform(X) [source]

Reverse the transformation operation  Parameters

Xarray of shape [n_samples, n_selected_features]

The input samples.    Returns

X_rarray of shape [n_samples, n_original_features]

X with columns of zeros inserted where features would have been removed by transform.

predict(X) [source]

 Reduce X to the selected features and then predict using the

underlying estimator.    Parameters

Xarray of shape [n_samples, n_features]

The input samples.    Returns

yarray of shape [n_samples]

The predicted target values.

predict_log_proba(X) [source]

Predict class log-probabilities for X.  Parameters

Xarray of shape [n_samples, n_features]

The input samples.    Returns

parray of shape (n_samples, n_classes)

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

predict_proba(X) [source]

Predict class probabilities for X.  Parameters

X{array-like or sparse matrix} of shape (n_samples, n_features)

The input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr_matrix.    Returns

parray of shape (n_samples, n_classes)

The class probabilities of the input samples. The order of the classes corresponds to that in the attribute classes_.

score(X, y) [source]

 Reduce X to the selected features and then return the score of the

underlying estimator.    Parameters

Xarray of shape [n_samples, n_features]

The input samples.
yarray of shape [n_samples]

The target values.

set_params(**params) [source]

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.  Parameters

**paramsdict

Estimator parameters.    Returns

selfestimator instance

Estimator instance.

transform(X) [source]

Reduce X to the selected features.  Parameters

Xarray of shape [n_samples, n_features]

The input samples.    Returns

X_rarray of shape [n_samples, n_selected_features]

The input samples with only the selected features.


sklearn.feature_selection.RFECV
class sklearn.feature_selection.RFECV(estimator, *, step=1, min_features_to_select=1, cv=None, scoring=None, verbose=0, n_jobs=None, importance_getter='auto') [source]

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.  Parameters

estimatorEstimator instance

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.
stepint or float, default=1

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.
min_features_to_selectint, default=1

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.
cvint, cross-validation generator or an iterable, default=None

Determines the cross-validation splitting strategy. Possible inputs for cv are:  None, to use the default 5-fold cross-validation, integer, to specify the number of folds.
CV splitter, An iterable yielding (train, test) splits as arrays of indices.  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.
scoringstring, callable or None, default=None

A string (see model evaluation documentation) or a scorer callable object / function with signature scorer(estimator, X, y).
verboseint, default=0

Controls verbosity of output.
n_jobsint or None, default=None

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.
importance_getterstr or callable, default=’auto’

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.     Attributes

estimator_Estimator instance

The fitted estimator used to select features.
grid_scores_ndarray of shape (n_subsets_of_features,)

The cross-validation scores such that grid_scores_[i] corresponds to the CV score of the i-th subset of features.
n_features_int

The number of selected features with cross-validation.
ranking_narray of shape (n_features,)

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.
support_ndarray of shape (n_features,)

The mask of selected features.      See also
RFE

Recursive feature elimination.    Notes 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. References
1
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.   Examples The following example shows how to retrieve the a-priori not known 5 informative features in the Friedman #1 dataset. >>> from sklearn.datasets import make_friedman1
>>> from sklearn.feature_selection import RFECV
>>> from sklearn.svm import SVR
>>> X, y = make_friedman1(n_samples=50, n_features=10, random_state=0)
>>> estimator = SVR(kernel="linear")
>>> selector = RFECV(estimator, step=1, cv=5)
>>> selector = selector.fit(X, y)
>>> selector.support_
array([ True,  True,  True,  True,  True, False, False, False, False,
       False])
>>> selector.ranking_
array([1, 1, 1, 1, 1, 6, 4, 3, 2, 5])
 Methods
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.
decision_function(X) [source]

Compute the decision function of X.  Parameters

X{array-like or sparse matrix} of shape (n_samples, n_features)

The input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr_matrix.    Returns

scorearray, shape = [n_samples, n_classes] or [n_samples]

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].

fit(X, y, groups=None) [source]

 Fit the RFE model and automatically tune the number of selected

features.    Parameters

X{array-like, sparse matrix} of shape (n_samples, n_features)

Training vector, where n_samples is the number of samples and n_features is the total number of features.
yarray-like of shape (n_samples,)

Target values (integers for classification, real numbers for regression).
groupsarray-like of shape (n_samples,) or None, default=None

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_transform(X, y=None, **fit_params) [source]

Fit to data, then transform it. Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.  Parameters

Xarray-like of shape (n_samples, n_features)

Input samples.
yarray-like of shape (n_samples,) or (n_samples, n_outputs), default=None

Target values (None for unsupervised transformations).
**fit_paramsdict

Additional fit parameters.    Returns

X_newndarray array of shape (n_samples, n_features_new)

Transformed array.

get_params(deep=True) [source]

Get parameters for this estimator.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.

get_support(indices=False) [source]

Get a mask, or integer index, of the features selected  Parameters

indicesbool, default=False

If True, the return value will be an array of integers, rather than a boolean mask.    Returns

supportarray

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.

inverse_transform(X) [source]

Reverse the transformation operation  Parameters

Xarray of shape [n_samples, n_selected_features]

The input samples.    Returns

X_rarray of shape [n_samples, n_original_features]

X with columns of zeros inserted where features would have been removed by transform.

predict(X) [source]

 Reduce X to the selected features and then predict using the

underlying estimator.    Parameters

Xarray of shape [n_samples, n_features]

The input samples.    Returns

yarray of shape [n_samples]

The predicted target values.

predict_log_proba(X) [source]

Predict class log-probabilities for X.  Parameters

Xarray of shape [n_samples, n_features]

The input samples.    Returns

parray of shape (n_samples, n_classes)

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

predict_proba(X) [source]

Predict class probabilities for X.  Parameters

X{array-like or sparse matrix} of shape (n_samples, n_features)

The input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr_matrix.    Returns

parray of shape (n_samples, n_classes)

The class probabilities of the input samples. The order of the classes corresponds to that in the attribute classes_.

score(X, y) [source]

 Reduce X to the selected features and then return the score of the

underlying estimator.    Parameters

Xarray of shape [n_samples, n_features]

The input samples.
yarray of shape [n_samples]

The target values.

set_params(**params) [source]

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.  Parameters

**paramsdict

Estimator parameters.    Returns

selfestimator instance

Estimator instance.

transform(X) [source]

Reduce X to the selected features.  Parameters

Xarray of shape [n_samples, n_features]

The input samples.    Returns

X_rarray of shape [n_samples, n_selected_features]

The input samples with only the selected features.

 Examples using sklearn.feature_selection.RFECV

  Recursive feature elimination with cross-validation


fit(X, y, groups=None) [source]

 Fit the RFE model and automatically tune the number of selected

features.    Parameters

X{array-like, sparse matrix} of shape (n_samples, n_features)

Training vector, where n_samples is the number of samples and n_features is the total number of features.
yarray-like of shape (n_samples,)

Target values (integers for classification, real numbers for regression).
groupsarray-like of shape (n_samples,) or None, default=None

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_transform(X, y=None, **fit_params) [source]

Fit to data, then transform it. Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.  Parameters

Xarray-like of shape (n_samples, n_features)

Input samples.
yarray-like of shape (n_samples,) or (n_samples, n_outputs), default=None

Target values (None for unsupervised transformations).
**fit_paramsdict

Additional fit parameters.    Returns

X_newndarray array of shape (n_samples, n_features_new)

Transformed array.


get_params(deep=True) [source]

Get parameters for this estimator.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.


get_support(indices=False) [source]

Get a mask, or integer index, of the features selected  Parameters

indicesbool, default=False

If True, the return value will be an array of integers, rather than a boolean mask.    Returns

supportarray

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.


inverse_transform(X) [source]

Reverse the transformation operation  Parameters

Xarray of shape [n_samples, n_selected_features]

The input samples.    Returns

X_rarray of shape [n_samples, n_original_features]

X with columns of zeros inserted where features would have been removed by transform.


set_params(**params) [source]

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.  Parameters

**paramsdict

Estimator parameters.    Returns

selfestimator instance

Estimator instance.


transform(X) [source]

Reduce X to the selected features.  Parameters

Xarray of shape [n_samples, n_features]

The input samples.    Returns

X_rarray of shape [n_samples, n_selected_features]

The input samples with only the selected features.


class sklearn.feature_selection.SelectFdr(score_func=<function f_classif>, *, alpha=0.05) [source]

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.  Parameters

score_funccallable, default=f_classif

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.
alphafloat, default=5e-2

The highest uncorrected p-value for features to keep.    Attributes

scores_array-like of shape (n_features,)

Scores of features.
pvalues_array-like of shape (n_features,)

p-values of feature scores.      See also
f_classif

ANOVA F-value between label/feature for classification tasks.
mutual_info_classif

Mutual information for a discrete target.
chi2

Chi-squared stats of non-negative features for classification tasks.
f_regression

F-value between label/feature for regression tasks.
mutual_info_regression

Mutual information for a contnuous target.
SelectPercentile

Select features based on percentile of the highest scores.
SelectKBest

Select features based on the k highest scores.
SelectFpr

Select features based on a false positive rate test.
SelectFwe

Select features based on family-wise error rate.
GenericUnivariateSelect

Univariate feature selector with configurable mode.    References https://en.wikipedia.org/wiki/False_discovery_rate Examples >>> from sklearn.datasets import load_breast_cancer
>>> from sklearn.feature_selection import SelectFdr, chi2
>>> X, y = load_breast_cancer(return_X_y=True)
>>> X.shape
(569, 30)
>>> X_new = SelectFdr(chi2, alpha=0.01).fit_transform(X, y)
>>> X_new.shape
(569, 16)
 Methods
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.
fit(X, y) [source]

Run score function on (X, y) and get the appropriate features.  Parameters

Xarray-like of shape (n_samples, n_features)

The training input samples.
yarray-like of shape (n_samples,)

The target values (class labels in classification, real numbers in regression).    Returns

selfobject

fit_transform(X, y=None, **fit_params) [source]

Fit to data, then transform it. Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.  Parameters

Xarray-like of shape (n_samples, n_features)

Input samples.
yarray-like of shape (n_samples,) or (n_samples, n_outputs), default=None

Target values (None for unsupervised transformations).
**fit_paramsdict

Additional fit parameters.    Returns

X_newndarray array of shape (n_samples, n_features_new)

Transformed array.

get_params(deep=True) [source]

Get parameters for this estimator.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.

get_support(indices=False) [source]

Get a mask, or integer index, of the features selected  Parameters

indicesbool, default=False

If True, the return value will be an array of integers, rather than a boolean mask.    Returns

supportarray

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.

inverse_transform(X) [source]

Reverse the transformation operation  Parameters

Xarray of shape [n_samples, n_selected_features]

The input samples.    Returns

X_rarray of shape [n_samples, n_original_features]

X with columns of zeros inserted where features would have been removed by transform.

set_params(**params) [source]

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.  Parameters

**paramsdict

Estimator parameters.    Returns

selfestimator instance

Estimator instance.

transform(X) [source]

Reduce X to the selected features.  Parameters

Xarray of shape [n_samples, n_features]

The input samples.    Returns

X_rarray of shape [n_samples, n_selected_features]

The input samples with only the selected features.


sklearn.feature_selection.SelectFdr
class sklearn.feature_selection.SelectFdr(score_func=<function f_classif>, *, alpha=0.05) [source]

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.  Parameters

score_funccallable, default=f_classif

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.
alphafloat, default=5e-2

The highest uncorrected p-value for features to keep.    Attributes

scores_array-like of shape (n_features,)

Scores of features.
pvalues_array-like of shape (n_features,)

p-values of feature scores.      See also
f_classif

ANOVA F-value between label/feature for classification tasks.
mutual_info_classif

Mutual information for a discrete target.
chi2

Chi-squared stats of non-negative features for classification tasks.
f_regression

F-value between label/feature for regression tasks.
mutual_info_regression

Mutual information for a contnuous target.
SelectPercentile

Select features based on percentile of the highest scores.
SelectKBest

Select features based on the k highest scores.
SelectFpr

Select features based on a false positive rate test.
SelectFwe

Select features based on family-wise error rate.
GenericUnivariateSelect

Univariate feature selector with configurable mode.    References https://en.wikipedia.org/wiki/False_discovery_rate Examples >>> from sklearn.datasets import load_breast_cancer
>>> from sklearn.feature_selection import SelectFdr, chi2
>>> X, y = load_breast_cancer(return_X_y=True)
>>> X.shape
(569, 30)
>>> X_new = SelectFdr(chi2, alpha=0.01).fit_transform(X, y)
>>> X_new.shape
(569, 16)
 Methods
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.
fit(X, y) [source]

Run score function on (X, y) and get the appropriate features.  Parameters

Xarray-like of shape (n_samples, n_features)

The training input samples.
yarray-like of shape (n_samples,)

The target values (class labels in classification, real numbers in regression).    Returns

selfobject

fit_transform(X, y=None, **fit_params) [source]

Fit to data, then transform it. Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.  Parameters

Xarray-like of shape (n_samples, n_features)

Input samples.
yarray-like of shape (n_samples,) or (n_samples, n_outputs), default=None

Target values (None for unsupervised transformations).
**fit_paramsdict

Additional fit parameters.    Returns

X_newndarray array of shape (n_samples, n_features_new)

Transformed array.

get_params(deep=True) [source]

Get parameters for this estimator.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.

get_support(indices=False) [source]

Get a mask, or integer index, of the features selected  Parameters

indicesbool, default=False

If True, the return value will be an array of integers, rather than a boolean mask.    Returns

supportarray

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.

inverse_transform(X) [source]

Reverse the transformation operation  Parameters

Xarray of shape [n_samples, n_selected_features]

The input samples.    Returns

X_rarray of shape [n_samples, n_original_features]

X with columns of zeros inserted where features would have been removed by transform.

set_params(**params) [source]

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.  Parameters

**paramsdict

Estimator parameters.    Returns

selfestimator instance

Estimator instance.

transform(X) [source]

Reduce X to the selected features.  Parameters

Xarray of shape [n_samples, n_features]

The input samples.    Returns

X_rarray of shape [n_samples, n_selected_features]

The input samples with only the selected features.


fit(X, y) [source]

Run score function on (X, y) and get the appropriate features.  Parameters

Xarray-like of shape (n_samples, n_features)

The training input samples.
yarray-like of shape (n_samples,)

The target values (class labels in classification, real numbers in regression).    Returns

selfobject


class sklearn.feature_selection.SelectFpr(score_func=<function f_classif>, *, alpha=0.05) [source]

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.  Parameters

score_funccallable, default=f_classif

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.
alphafloat, default=5e-2

The highest p-value for features to be kept.    Attributes

scores_array-like of shape (n_features,)

Scores of features.
pvalues_array-like of shape (n_features,)

p-values of feature scores.      See also
f_classif

ANOVA F-value between label/feature for classification tasks.
chi2

Chi-squared stats of non-negative features for classification tasks.
mutual_info_classif

Mutual information for a discrete target.
f_regression

F-value between label/feature for regression tasks.
mutual_info_regression

Mutual information for a continuous target.
SelectPercentile

Select features based on percentile of the highest scores.
SelectKBest

Select features based on the k highest scores.
SelectFdr

Select features based on an estimated false discovery rate.
SelectFwe

Select features based on family-wise error rate.
GenericUnivariateSelect

Univariate feature selector with configurable mode.    Examples >>> from sklearn.datasets import load_breast_cancer
>>> from sklearn.feature_selection import SelectFpr, chi2
>>> X, y = load_breast_cancer(return_X_y=True)
>>> X.shape
(569, 30)
>>> X_new = SelectFpr(chi2, alpha=0.01).fit_transform(X, y)
>>> X_new.shape
(569, 16)
 Methods
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.
fit(X, y) [source]

Run score function on (X, y) and get the appropriate features.  Parameters

Xarray-like of shape (n_samples, n_features)

The training input samples.
yarray-like of shape (n_samples,)

The target values (class labels in classification, real numbers in regression).    Returns

selfobject

fit_transform(X, y=None, **fit_params) [source]

Fit to data, then transform it. Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.  Parameters

Xarray-like of shape (n_samples, n_features)

Input samples.
yarray-like of shape (n_samples,) or (n_samples, n_outputs), default=None

Target values (None for unsupervised transformations).
**fit_paramsdict

Additional fit parameters.    Returns

X_newndarray array of shape (n_samples, n_features_new)

Transformed array.

get_params(deep=True) [source]

Get parameters for this estimator.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.

get_support(indices=False) [source]

Get a mask, or integer index, of the features selected  Parameters

indicesbool, default=False

If True, the return value will be an array of integers, rather than a boolean mask.    Returns

supportarray

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.

inverse_transform(X) [source]

Reverse the transformation operation  Parameters

Xarray of shape [n_samples, n_selected_features]

The input samples.    Returns

X_rarray of shape [n_samples, n_original_features]

X with columns of zeros inserted where features would have been removed by transform.

set_params(**params) [source]

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.  Parameters

**paramsdict

Estimator parameters.    Returns

selfestimator instance

Estimator instance.

transform(X) [source]

Reduce X to the selected features.  Parameters

Xarray of shape [n_samples, n_features]

The input samples.    Returns

X_rarray of shape [n_samples, n_selected_features]

The input samples with only the selected features.


sklearn.feature_selection.SelectFpr
class sklearn.feature_selection.SelectFpr(score_func=<function f_classif>, *, alpha=0.05) [source]

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.  Parameters

score_funccallable, default=f_classif

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.
alphafloat, default=5e-2

The highest p-value for features to be kept.    Attributes

scores_array-like of shape (n_features,)

Scores of features.
pvalues_array-like of shape (n_features,)

p-values of feature scores.      See also
f_classif

ANOVA F-value between label/feature for classification tasks.
chi2

Chi-squared stats of non-negative features for classification tasks.
mutual_info_classif

Mutual information for a discrete target.
f_regression

F-value between label/feature for regression tasks.
mutual_info_regression

Mutual information for a continuous target.
SelectPercentile

Select features based on percentile of the highest scores.
SelectKBest

Select features based on the k highest scores.
SelectFdr

Select features based on an estimated false discovery rate.
SelectFwe

Select features based on family-wise error rate.
GenericUnivariateSelect

Univariate feature selector with configurable mode.    Examples >>> from sklearn.datasets import load_breast_cancer
>>> from sklearn.feature_selection import SelectFpr, chi2
>>> X, y = load_breast_cancer(return_X_y=True)
>>> X.shape
(569, 30)
>>> X_new = SelectFpr(chi2, alpha=0.01).fit_transform(X, y)
>>> X_new.shape
(569, 16)
 Methods
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.
fit(X, y) [source]

Run score function on (X, y) and get the appropriate features.  Parameters

Xarray-like of shape (n_samples, n_features)

The training input samples.
yarray-like of shape (n_samples,)

The target values (class labels in classification, real numbers in regression).    Returns

selfobject

fit_transform(X, y=None, **fit_params) [source]

Fit to data, then transform it. Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.  Parameters

Xarray-like of shape (n_samples, n_features)

Input samples.
yarray-like of shape (n_samples,) or (n_samples, n_outputs), default=None

Target values (None for unsupervised transformations).
**fit_paramsdict

Additional fit parameters.    Returns

X_newndarray array of shape (n_samples, n_features_new)

Transformed array.

get_params(deep=True) [source]

Get parameters for this estimator.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.

get_support(indices=False) [source]

Get a mask, or integer index, of the features selected  Parameters

indicesbool, default=False

If True, the return value will be an array of integers, rather than a boolean mask.    Returns

supportarray

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.

inverse_transform(X) [source]

Reverse the transformation operation  Parameters

Xarray of shape [n_samples, n_selected_features]

The input samples.    Returns

X_rarray of shape [n_samples, n_original_features]

X with columns of zeros inserted where features would have been removed by transform.

set_params(**params) [source]

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.  Parameters

**paramsdict

Estimator parameters.    Returns

selfestimator instance

Estimator instance.

transform(X) [source]

Reduce X to the selected features.  Parameters

Xarray of shape [n_samples, n_features]

The input samples.    Returns

X_rarray of shape [n_samples, n_selected_features]

The input samples with only the selected features.


class sklearn.feature_selection.SelectFromModel(estimator, *, threshold=None, prefit=False, norm_order=1, max_features=None, importance_getter='auto') [source]

Meta-transformer for selecting features based on importance weights.  New in version 0.17.  Read more in the User Guide.  Parameters

estimatorobject

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.
thresholdstring or float, default=None

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.
prefitbool, default=False

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.
norm_ordernon-zero int, inf, -inf, default=1

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.
max_featuresint, default=None

The maximum number of features to select. To only select based on max_features, set threshold=-np.inf.  New in version 0.20.
importance_getterstr or callable, default=’auto’

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.     Attributes

estimator_an estimator

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.
threshold_float

The threshold value used for feature selection.      See also
RFE

Recursive feature elimination based on importance weights.
RFECV

Recursive feature elimination with built-in cross-validated selection of the best number of features.
SequentialFeatureSelector

Sequential cross-validation based feature selection. Does not rely on importance weights.    Notes Allows NaN/Inf in the input if the underlying estimator does as well. Examples >>> from sklearn.feature_selection import SelectFromModel
>>> from sklearn.linear_model import LogisticRegression
>>> X = [[ 0.87, -1.34,  0.31 ],
...      [-2.79, -0.02, -0.85 ],
...      [-1.34, -0.48, -2.55 ],
...      [ 1.92,  1.48,  0.65 ]]
>>> y = [0, 1, 0, 1]
>>> selector = SelectFromModel(estimator=LogisticRegression()).fit(X, y)
>>> selector.estimator_.coef_
array([[-0.3252302 ,  0.83462377,  0.49750423]])
>>> selector.threshold_
0.55245...
>>> selector.get_support()
array([False,  True, False])
>>> selector.transform(X)
array([[-1.34],
       [-0.02],
       [-0.48],
       [ 1.48]])
 Methods
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(X, y=None, **fit_params) [source]

Fit the SelectFromModel meta-transformer.  Parameters

Xarray-like of shape (n_samples, n_features)

The training input samples.
yarray-like of shape (n_samples,), default=None

The target values (integers that correspond to classes in classification, real numbers in regression).
**fit_paramsOther estimator specific parameters
  Returns

selfobject

fit_transform(X, y=None, **fit_params) [source]

Fit to data, then transform it. Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.  Parameters

Xarray-like of shape (n_samples, n_features)

Input samples.
yarray-like of shape (n_samples,) or (n_samples, n_outputs), default=None

Target values (None for unsupervised transformations).
**fit_paramsdict

Additional fit parameters.    Returns

X_newndarray array of shape (n_samples, n_features_new)

Transformed array.

get_params(deep=True) [source]

Get parameters for this estimator.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.

get_support(indices=False) [source]

Get a mask, or integer index, of the features selected  Parameters

indicesbool, default=False

If True, the return value will be an array of integers, rather than a boolean mask.    Returns

supportarray

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.

inverse_transform(X) [source]

Reverse the transformation operation  Parameters

Xarray of shape [n_samples, n_selected_features]

The input samples.    Returns

X_rarray of shape [n_samples, n_original_features]

X with columns of zeros inserted where features would have been removed by transform.

partial_fit(X, y=None, **fit_params) [source]

Fit the SelectFromModel meta-transformer only once.  Parameters

Xarray-like of shape (n_samples, n_features)

The training input samples.
yarray-like of shape (n_samples,), default=None

The target values (integers that correspond to classes in classification, real numbers in regression).
**fit_paramsOther estimator specific parameters
  Returns

selfobject

set_params(**params) [source]

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.  Parameters

**paramsdict

Estimator parameters.    Returns

selfestimator instance

Estimator instance.

transform(X) [source]

Reduce X to the selected features.  Parameters

Xarray of shape [n_samples, n_features]

The input samples.    Returns

X_rarray of shape [n_samples, n_selected_features]

The input samples with only the selected features.


sklearn.feature_selection.SelectFromModel
class sklearn.feature_selection.SelectFromModel(estimator, *, threshold=None, prefit=False, norm_order=1, max_features=None, importance_getter='auto') [source]

Meta-transformer for selecting features based on importance weights.  New in version 0.17.  Read more in the User Guide.  Parameters

estimatorobject

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.
thresholdstring or float, default=None

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.
prefitbool, default=False

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.
norm_ordernon-zero int, inf, -inf, default=1

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.
max_featuresint, default=None

The maximum number of features to select. To only select based on max_features, set threshold=-np.inf.  New in version 0.20.
importance_getterstr or callable, default=’auto’

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.     Attributes

estimator_an estimator

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.
threshold_float

The threshold value used for feature selection.      See also
RFE

Recursive feature elimination based on importance weights.
RFECV

Recursive feature elimination with built-in cross-validated selection of the best number of features.
SequentialFeatureSelector

Sequential cross-validation based feature selection. Does not rely on importance weights.    Notes Allows NaN/Inf in the input if the underlying estimator does as well. Examples >>> from sklearn.feature_selection import SelectFromModel
>>> from sklearn.linear_model import LogisticRegression
>>> X = [[ 0.87, -1.34,  0.31 ],
...      [-2.79, -0.02, -0.85 ],
...      [-1.34, -0.48, -2.55 ],
...      [ 1.92,  1.48,  0.65 ]]
>>> y = [0, 1, 0, 1]
>>> selector = SelectFromModel(estimator=LogisticRegression()).fit(X, y)
>>> selector.estimator_.coef_
array([[-0.3252302 ,  0.83462377,  0.49750423]])
>>> selector.threshold_
0.55245...
>>> selector.get_support()
array([False,  True, False])
>>> selector.transform(X)
array([[-1.34],
       [-0.02],
       [-0.48],
       [ 1.48]])
 Methods
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(X, y=None, **fit_params) [source]

Fit the SelectFromModel meta-transformer.  Parameters

Xarray-like of shape (n_samples, n_features)

The training input samples.
yarray-like of shape (n_samples,), default=None

The target values (integers that correspond to classes in classification, real numbers in regression).
**fit_paramsOther estimator specific parameters
  Returns

selfobject

fit_transform(X, y=None, **fit_params) [source]

Fit to data, then transform it. Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.  Parameters

Xarray-like of shape (n_samples, n_features)

Input samples.
yarray-like of shape (n_samples,) or (n_samples, n_outputs), default=None

Target values (None for unsupervised transformations).
**fit_paramsdict

Additional fit parameters.    Returns

X_newndarray array of shape (n_samples, n_features_new)

Transformed array.

get_params(deep=True) [source]

Get parameters for this estimator.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.

get_support(indices=False) [source]

Get a mask, or integer index, of the features selected  Parameters

indicesbool, default=False

If True, the return value will be an array of integers, rather than a boolean mask.    Returns

supportarray

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.

inverse_transform(X) [source]

Reverse the transformation operation  Parameters

Xarray of shape [n_samples, n_selected_features]

The input samples.    Returns

X_rarray of shape [n_samples, n_original_features]

X with columns of zeros inserted where features would have been removed by transform.

partial_fit(X, y=None, **fit_params) [source]

Fit the SelectFromModel meta-transformer only once.  Parameters

Xarray-like of shape (n_samples, n_features)

The training input samples.
yarray-like of shape (n_samples,), default=None

The target values (integers that correspond to classes in classification, real numbers in regression).
**fit_paramsOther estimator specific parameters
  Returns

selfobject

set_params(**params) [source]

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.  Parameters

**paramsdict

Estimator parameters.    Returns

selfestimator instance

Estimator instance.

transform(X) [source]

Reduce X to the selected features.  Parameters

Xarray of shape [n_samples, n_features]

The input samples.    Returns

X_rarray of shape [n_samples, n_selected_features]

The input samples with only the selected features.

 Examples using sklearn.feature_selection.SelectFromModel

  Model-based and sequential feature selection

  Classification of text documents using sparse features


fit(X, y=None, **fit_params) [source]

Fit the SelectFromModel meta-transformer.  Parameters

Xarray-like of shape (n_samples, n_features)

The training input samples.
yarray-like of shape (n_samples,), default=None

The target values (integers that correspond to classes in classification, real numbers in regression).
**fit_paramsOther estimator specific parameters
  Returns

selfobject


partial_fit(X, y=None, **fit_params) [source]

Fit the SelectFromModel meta-transformer only once.  Parameters

Xarray-like of shape (n_samples, n_features)

The training input samples.
yarray-like of shape (n_samples,), default=None

The target values (integers that correspond to classes in classification, real numbers in regression).
**fit_paramsOther estimator specific parameters
  Returns

selfobject


class sklearn.feature_selection.SelectFwe(score_func=<function f_classif>, *, alpha=0.05) [source]

Filter: Select the p-values corresponding to Family-wise error rate Read more in the User Guide.  Parameters

score_funccallable, default=f_classif

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.
alphafloat, default=5e-2

The highest uncorrected p-value for features to keep.    Attributes

scores_array-like of shape (n_features,)

Scores of features.
pvalues_array-like of shape (n_features,)

p-values of feature scores.      See also
f_classif

ANOVA F-value between label/feature for classification tasks.
chi2

Chi-squared stats of non-negative features for classification tasks.
f_regression

F-value between label/feature for regression tasks.
SelectPercentile

Select features based on percentile of the highest scores.
SelectKBest

Select features based on the k highest scores.
SelectFpr

Select features based on a false positive rate test.
SelectFdr

Select features based on an estimated false discovery rate.
GenericUnivariateSelect

Univariate feature selector with configurable mode.    Examples >>> from sklearn.datasets import load_breast_cancer
>>> from sklearn.feature_selection import SelectFwe, chi2
>>> X, y = load_breast_cancer(return_X_y=True)
>>> X.shape
(569, 30)
>>> X_new = SelectFwe(chi2, alpha=0.01).fit_transform(X, y)
>>> X_new.shape
(569, 15)
 Methods
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.
fit(X, y) [source]

Run score function on (X, y) and get the appropriate features.  Parameters

Xarray-like of shape (n_samples, n_features)

The training input samples.
yarray-like of shape (n_samples,)

The target values (class labels in classification, real numbers in regression).    Returns

selfobject

fit_transform(X, y=None, **fit_params) [source]

Fit to data, then transform it. Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.  Parameters

Xarray-like of shape (n_samples, n_features)

Input samples.
yarray-like of shape (n_samples,) or (n_samples, n_outputs), default=None

Target values (None for unsupervised transformations).
**fit_paramsdict

Additional fit parameters.    Returns

X_newndarray array of shape (n_samples, n_features_new)

Transformed array.

get_params(deep=True) [source]

Get parameters for this estimator.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.

get_support(indices=False) [source]

Get a mask, or integer index, of the features selected  Parameters

indicesbool, default=False

If True, the return value will be an array of integers, rather than a boolean mask.    Returns

supportarray

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.

inverse_transform(X) [source]

Reverse the transformation operation  Parameters

Xarray of shape [n_samples, n_selected_features]

The input samples.    Returns

X_rarray of shape [n_samples, n_original_features]

X with columns of zeros inserted where features would have been removed by transform.

set_params(**params) [source]

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.  Parameters

**paramsdict

Estimator parameters.    Returns

selfestimator instance

Estimator instance.

transform(X) [source]

Reduce X to the selected features.  Parameters

Xarray of shape [n_samples, n_features]

The input samples.    Returns

X_rarray of shape [n_samples, n_selected_features]

The input samples with only the selected features.