Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[MRG] Apply numpydoc validation to VotingRegressor methods #15500

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions maint_tools/test_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
"RidgeClassifier.fit",
"RidgeClassifierCV.decision_function",
"SGDClassifier.decision_function",
"VotingRegressor$",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unfamiliar with this $ notation. I see it above for LogisticRegression$ and not below for KernelDensity. What does it mean and what made you decide to put $?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It means end of the string with regular expression. LogisticRegression without $ would match any of its methods, not just the main docstring

"VotingRegressor.fit",
"VotingRegressor.transform",
"VotingRegressor.predict",
"VotingRegressor.score",
"KernelDensity",
"KernelDensity.fit",
"KernelDensity.score",
Expand Down
6 changes: 4 additions & 2 deletions sklearn/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the convention has been to write "Returns"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is okay since we follow https://www.python.org/dev/peps/pep-0257/

The docstring is a phrase ending in a period. It prescribes the function or method's effect as a command ("Do this", "Return that"), not as a description; e.g. don't write "Returns the pathname ...".


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
Expand Down Expand Up @@ -549,11 +549,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe say "dict of keyword arguments"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**fit_params : Any number of parameters
**fit_params : dict

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
Expand Down
15 changes: 8 additions & 7 deletions sklearn/ensemble/_voting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -359,6 +359,10 @@ class VotingRegressor(RegressorMixin, _BaseVoting):

.. versionadded:: 0.20

See Also
--------
VotingClassifier: Soft Voting/Majority Rule classifier.

Examples
--------
>>> import numpy as np
Expand All @@ -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):
Expand All @@ -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
----------
Expand All @@ -403,6 +403,7 @@ def fit(self, X, y, sample_weight=None):
Returns
-------
self : object
Returns self.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Returns self.
Fitted estimator.

although I agree that it's probably not very useful in any case.

"""
y = column_or_1d(y, warn=True)
return super().fit(X, y, sample_weight)
Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no actually this should be,

predictions : array-like of shape (n_samples, n_classifiers)
    Values predicted by each regressor.

(with the right indentation)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of curiosity, why should this be an array-like instead of an array. Can it output anything other than ndarrays? (My only guess would be that if a dataframe was input it could output one and that dfs fall under the array-like definition, but haven't followed in detail the inclusion of dfs as possible inputs)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, it can only return an array. We use array-like for input dtypes, and it was probably copy-pasted there...

values predicted by each regressor.
"""
check_is_fitted(self)
Expand Down