Skip to content

DOC Ensures that RFECV passes numpydoc validation #20452

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jul 7, 2021
1 change: 0 additions & 1 deletion maint_tools/test_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@
"RANSACRegressor",
"RBFSampler",
"RFE",
"RFECV",
"RadiusNeighborsClassifier",
"RadiusNeighborsRegressor",
"RadiusNeighborsTransformer",
Expand Down
5 changes: 2 additions & 3 deletions sklearn/feature_selection/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SelectorMixin(TransformerMixin, metaclass=ABCMeta):

def get_support(self, indices=False):
"""
Get a mask, or integer index, of the features selected
Get a mask, or integer index, of the features selected.

Parameters
----------
Expand Down Expand Up @@ -99,8 +99,7 @@ def transform(self, X):
return X[:, safe_mask(X, mask)]

def inverse_transform(self, X):
"""
Reverse the transformation operation
"""Reverse the transformation operation.

Parameters
----------
Expand Down
43 changes: 29 additions & 14 deletions sklearn/feature_selection/_rfe.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ def _estimator_type(self):

@property
def classes_(self):
"""Classes labels available when `estimator` is a classifier.

Returns
-------
ndarray of shape (n_classes,)
"""
return self.estimator_.classes_

def fit(self, X, y):
Expand All @@ -196,6 +202,11 @@ def fit(self, X, y):

y : array-like of shape (n_samples,)
The target values.

Returns
-------
self : object
Fitted estimator.
"""
return self._fit(X, y)

Expand Down Expand Up @@ -407,8 +418,7 @@ def _more_tags(self):


class RFECV(RFE):
"""Feature ranking with recursive feature elimination and cross-validated
selection of the best number of features.
"""Recursive feature elimination with cross-validation to select the number of features.

See glossary entry for :term:`cross-validation estimator`.

Expand Down Expand Up @@ -457,7 +467,7 @@ class RFECV(RFE):
.. versionchanged:: 0.22
``cv`` default value of None changed from 3-fold to 5-fold.

scoring : string, callable or None, default=None
scoring : str, callable or None, default=None
A string (see model evaluation documentation) or
a scorer callable object / function with signature
``scorer(estimator, X, y)``.
Expand Down Expand Up @@ -522,6 +532,10 @@ class RFECV(RFE):
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
Expand All @@ -530,6 +544,13 @@ class RFECV(RFE):

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
Expand All @@ -547,17 +568,6 @@ class RFECV(RFE):
False])
>>> selector.ranking_
array([1, 1, 1, 1, 1, 6, 4, 3, 2, 5])

See Also
--------
RFE : Recursive feature elimination.

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

def __init__(
Expand Down Expand Up @@ -600,6 +610,11 @@ def fit(self, X, y, groups=None):
instance (e.g., :class:`~sklearn.model_selection.GroupKFold`).

.. versionadded:: 0.20

Returns
-------
self : object
Fitted estimator.
"""
tags = self._get_tags()
X, y = self._validate_data(
Expand Down