From 3ba7675f36ba87348107a76dc5a6df5a741d739b Mon Sep 17 00:00:00 2001 From: judithabk6 Date: Wed, 29 Jan 2020 14:22:23 +0100 Subject: [PATCH 1/5] implement test for documentation of the classes_ attribute from PR #12509 by @jrbourbeau --- sklearn/tests/test_docstring_parameters.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sklearn/tests/test_docstring_parameters.py b/sklearn/tests/test_docstring_parameters.py index 28af419195813..34edcecdb6b71 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): + pytest.importorskip('numpydoc') + from numpydoc import docscrape + + doc = docscrape.ClassDoc(Classifier) + attributes = doc['Attributes'] + assert attributes + assert any(['classes_' in att[0] for att in attributes]) From 5901bf333f9b113e92cf737cd4e652e60772455d Mon Sep 17 00:00:00 2001 From: judithabk6 Date: Wed, 29 Jan 2020 15:35:34 +0100 Subject: [PATCH 2/5] adding documentation for the classes_ attribute where it was missing --- .../ensemble/_hist_gradient_boosting/gradient_boosting.py | 2 ++ sklearn/ensemble/_stacking.py | 3 +++ sklearn/multioutput.py | 3 +++ sklearn/utils/_mocking.py | 6 ++++++ 4 files changed, 14 insertions(+) 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/utils/_mocking.py b/sklearn/utils/_mocking.py index 3edcf8da53a95..20f2c3e5852e0 100644 --- a/sklearn/utils/_mocking.py +++ b/sklearn/utils/_mocking.py @@ -61,6 +61,12 @@ class CheckingClassifier(ClassifierMixin, BaseEstimator): check_X foo_param expected_fit_params + + Attributes + ---------- + classes_ : array, shape = (n_classes,) + Class labels. + """ def __init__(self, check_y=None, check_X=None, foo_param=0, expected_fit_params=None): From 047a7becf45f7d72aeee1d9ed96a11df391845ea Mon Sep 17 00:00:00 2001 From: judithabk6 Date: Wed, 29 Jan 2020 15:46:44 +0100 Subject: [PATCH 3/5] Update import of all_estimators Co-Authored-By: Alexandre Gramfort --- sklearn/tests/test_docstring_parameters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearn/tests/test_docstring_parameters.py b/sklearn/tests/test_docstring_parameters.py index 34edcecdb6b71..55d447e3bdb6c 100644 --- a/sklearn/tests/test_docstring_parameters.py +++ b/sklearn/tests/test_docstring_parameters.py @@ -15,7 +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._testing import all_estimators from sklearn.utils.deprecation import _is_deprecated from sklearn.externals._pep562 import Pep562 From fd1334f89d0d1e2780f4bfd642d27727fc7fb14b Mon Sep 17 00:00:00 2001 From: judithabk6 Date: Wed, 29 Jan 2020 17:34:16 +0100 Subject: [PATCH 4/5] implement minimal documentation as private class --- sklearn/utils/_mocking.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sklearn/utils/_mocking.py b/sklearn/utils/_mocking.py index 20f2c3e5852e0..e7525460fc975 100644 --- a/sklearn/utils/_mocking.py +++ b/sklearn/utils/_mocking.py @@ -64,8 +64,7 @@ class CheckingClassifier(ClassifierMixin, BaseEstimator): Attributes ---------- - classes_ : array, shape = (n_classes,) - Class labels. + classes_ """ def __init__(self, check_y=None, check_X=None, foo_param=0, From e5db026bc56001eeb423c35bd83f2c0f9624f5d0 Mon Sep 17 00:00:00 2001 From: judithabk6 Date: Fri, 31 Jan 2020 10:44:46 +0100 Subject: [PATCH 5/5] slight changes in test for attribute classes_ documentation --- sklearn/tests/test_docstring_parameters.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sklearn/tests/test_docstring_parameters.py b/sklearn/tests/test_docstring_parameters.py index 55d447e3bdb6c..b0f3d9e336e8d 100644 --- a/sklearn/tests/test_docstring_parameters.py +++ b/sklearn/tests/test_docstring_parameters.py @@ -166,10 +166,10 @@ def test_tabs(): @pytest.mark.parametrize('name, Classifier', all_estimators(type_filter='classifier')) def test_classifier_docstring_attributes(name, Classifier): - pytest.importorskip('numpydoc') + docscrape = pytest.importorskip('numpydoc.docscrape') from numpydoc import docscrape doc = docscrape.ClassDoc(Classifier) attributes = doc['Attributes'] assert attributes - assert any(['classes_' in att[0] for att in attributes]) + assert 'classes_' in [att.name for att in attributes]