diff --git a/sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py b/sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py index f3efd3c897a4c..4bbcb6db48b90 100644 --- a/sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py +++ b/sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py @@ -923,6 +923,8 @@ class HistGradientBoostingClassifier(BaseHistGradientBoosting, Attributes ---------- + classes_ : array, shape = (n_classes,) + Class labels. n_iter_ : int The number of estimators as selected by early stopping (if n_iter_no_change is not None). Otherwise it corresponds to max_iter. diff --git a/sklearn/ensemble/_stacking.py b/sklearn/ensemble/_stacking.py index db3d3508a46ba..f99f2be66dfac 100644 --- a/sklearn/ensemble/_stacking.py +++ b/sklearn/ensemble/_stacking.py @@ -312,6 +312,9 @@ class StackingClassifier(ClassifierMixin, _BaseStacking): Attributes ---------- + classes_ : array, shape = (n_classes,) + Class labels. + estimators_ : list of estimators The elements of the estimators parameter, having been fitted on the training data. If an estimator has been set to `'drop'`, it diff --git a/sklearn/multioutput.py b/sklearn/multioutput.py index 90e393e19503a..c4a11edced828 100644 --- a/sklearn/multioutput.py +++ b/sklearn/multioutput.py @@ -288,6 +288,9 @@ class MultiOutputClassifier(ClassifierMixin, _MultiOutputEstimator): Attributes ---------- + classes_ : array, shape = (n_classes,) + Class labels. + estimators_ : list of ``n_output`` estimators Estimators used for predictions. diff --git a/sklearn/tests/test_docstring_parameters.py b/sklearn/tests/test_docstring_parameters.py index 28af419195813..b0f3d9e336e8d 100644 --- a/sklearn/tests/test_docstring_parameters.py +++ b/sklearn/tests/test_docstring_parameters.py @@ -15,6 +15,7 @@ from sklearn.utils._testing import check_docstring_parameters from sklearn.utils._testing import _get_func_name from sklearn.utils._testing import ignore_warnings +from sklearn.utils._testing import all_estimators from sklearn.utils.deprecation import _is_deprecated from sklearn.externals._pep562 import Pep562 @@ -160,3 +161,15 @@ def test_tabs(): assert '\t' not in source, ('"%s" has tabs, please remove them ', 'or add it to theignore list' % modname) + + +@pytest.mark.parametrize('name, Classifier', + all_estimators(type_filter='classifier')) +def test_classifier_docstring_attributes(name, Classifier): + docscrape = pytest.importorskip('numpydoc.docscrape') + from numpydoc import docscrape + + doc = docscrape.ClassDoc(Classifier) + attributes = doc['Attributes'] + assert attributes + assert 'classes_' in [att.name for att in attributes] diff --git a/sklearn/utils/_mocking.py b/sklearn/utils/_mocking.py index 3edcf8da53a95..e7525460fc975 100644 --- a/sklearn/utils/_mocking.py +++ b/sklearn/utils/_mocking.py @@ -61,6 +61,11 @@ class CheckingClassifier(ClassifierMixin, BaseEstimator): check_X foo_param expected_fit_params + + Attributes + ---------- + classes_ + """ def __init__(self, check_y=None, check_X=None, foo_param=0, expected_fit_params=None):