From a040a331b1dc529bbafa70de53884a215f2dc32e Mon Sep 17 00:00:00 2001 From: "Tiffany R. Williams" Date: Sat, 2 Nov 2019 13:51:41 -0700 Subject: [PATCH] Apply numpydoc validation to VotingRegressor methods -m - - --- maint_tools/test_docstrings.py | 5 +++++ sklearn/base.py | 6 ++++-- sklearn/ensemble/_voting.py | 15 ++++++++------- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/maint_tools/test_docstrings.py b/maint_tools/test_docstrings.py index 7c0c2c8191880..abecafb452098 100644 --- a/maint_tools/test_docstrings.py +++ b/maint_tools/test_docstrings.py @@ -22,6 +22,11 @@ "RidgeClassifier.decision_function", "RidgeClassifierCV.decision_function", "SGDClassifier.decision_function", + "VotingRegressor$", + "VotingRegressor.fit", + "VotingRegressor.transform", + "VotingRegressor.predict", + "VotingRegressor.score", ] diff --git a/sklearn/base.py b/sklearn/base.py index 2ec022c2d6da1..dff9e058de4d4 100644 --- a/sklearn/base.py +++ b/sklearn/base.py @@ -369,7 +369,7 @@ class RegressorMixin: _estimator_type = "regressor" def score(self, X, y, sample_weight=None): - """Returns the coefficient of determination R^2 of the prediction. + """Return the coefficient of determination R^2 of the prediction. The coefficient R^2 is defined as (1 - u/v), where u is the residual sum of squares ((y_true - y_pred) ** 2).sum() and v is the total @@ -548,11 +548,13 @@ def fit_transform(self, X, y=None, **fit_params): y : numpy array of shape [n_samples] Target values. + **fit_params : Any number of parameters + Fit parameters. + Returns ------- X_new : numpy array of shape [n_samples, n_features_new] Transformed array. - """ # non-optimized default implementation; override when a better # method is possible for a given clustering algorithm diff --git a/sklearn/ensemble/_voting.py b/sklearn/ensemble/_voting.py index bddf5f00b10af..d1074c6b4b65d 100644 --- a/sklearn/ensemble/_voting.py +++ b/sklearn/ensemble/_voting.py @@ -328,7 +328,7 @@ class VotingRegressor(RegressorMixin, _BaseVoting): Parameters ---------- - estimators : list of (string, estimator) tuples + estimators : list of (str, estimator) tuples Invoking the ``fit`` method on the ``VotingRegressor`` will fit clones of those original estimators that will be stored in the class attribute ``self.estimators_``. An estimator can be set to ``'drop'`` using @@ -359,6 +359,10 @@ class VotingRegressor(RegressorMixin, _BaseVoting): .. versionadded:: 0.20 + See Also + -------- + VotingClassifier: Soft Voting/Majority Rule classifier. + Examples -------- >>> import numpy as np @@ -372,10 +376,6 @@ class VotingRegressor(RegressorMixin, _BaseVoting): >>> er = VotingRegressor([('lr', r1), ('rf', r2)]) >>> print(er.fit(X, y).predict(X)) [ 3.3 5.7 11.8 19.7 28. 40.3] - - See also - -------- - VotingClassifier: Soft Voting/Majority Rule classifier. """ def __init__(self, estimators, weights=None, n_jobs=None): @@ -384,7 +384,7 @@ def __init__(self, estimators, weights=None, n_jobs=None): self.n_jobs = n_jobs def fit(self, X, y, sample_weight=None): - """ Fit the estimators. + """Fit the estimators. Parameters ---------- @@ -403,6 +403,7 @@ def fit(self, X, y, sample_weight=None): Returns ------- self : object + Returns self. """ y = column_or_1d(y, warn=True) return super().fit(X, y, sample_weight) @@ -438,7 +439,7 @@ def transform(self, X): Returns ------- predictions - array-like of shape (n_samples, n_classifiers), being + Array-like of shape (n_samples, n_classifiers), being values predicted by each regressor. """ check_is_fitted(self)