8000 DOC Ensures that OneVsRestClassifier passes numpydoc validation by bharatr21 · Pull Request #21014 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

DOC Ensures that OneVsRestClassifier passes numpydoc validation #21014

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 3 commits into from
Sep 13, 2021
Merged
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
1 change: 0 additions & 1 deletion maint_tools/test_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"NearestCentroid",
"NeighborhoodComponentsAnalysis",
"Normalizer",
"OneVsRestClassifier",
"OrdinalEncoder",
"OrthogonalMatchingPursuit",
"OrthogonalMatchingPursuitCV",
Expand Down
36 changes: 22 additions & 14 deletions sklearn/multiclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,13 @@ class OneVsRestClassifier(

.. versionadded:: 1.0

See Also
--------
MultiOutputClassifier : Alternate way of extending an estimator for
multilabel classification.
sklearn.preprocessing.MultiLabelBinarizer : Transform iterable of iterables
to binary indicator matrix.

Examples
--------
>>> import numpy as np
Expand All @@ -292,13 +299,6 @@ class OneVsRestClassifier(
>>> clf = OneVsRestClassifier(SVC()).fit(X, y)
>>> clf.predict([[-19, -20], [9, 9], [-5, 5]])
array([2, 0, 1])

See Also
--------
sklearn.multioutput.MultiOutputClassifier : Alternate way of extending an
estimator for multilabel classification.
sklearn.preprocessing.MultiLabelBinarizer : Transform iterable of iterables
to binary indicator matrix.
"""

def __init__(self, estimator, *, n_jobs=None):
Expand All @@ -319,7 +319,8 @@ def fit(self, X, y):

Returns
-------
self
self : object
Instance of fitted estimator.
"""
# A sparse LabelBinarizer, with sparse_output=True, has been shown to
# outperform or match a dense label binarizer in all cases and has also
Expand Down Expand Up @@ -355,7 +356,7 @@ def fit(self, X, y):

@available_if(_estimators_has("partial_fit"))
def partial_fit(self, X, y, classes=None):
"""Partially fit underlying estimators
"""Partially fit underlying estimators.

Should be used when memory is inefficient to train all data.
Chunks of data can be passed in several iteration.
Expand All @@ -378,7 +379,8 @@ def partial_fit(self, X, y, classes=None):

Returns
-------
self
self : object
Instance of partially fitted estimator.
"""
if _check_partial_fit_first_call(self, classes):
if not hasattr(self.estimator, "partial_fit"):
Expand Down Expand Up @@ -477,6 +479,7 @@ def predict_proba(self, X):
Parameters
----------
X : array-like of shape (n_samples, n_features)
Input data.

Returns
-------
Expand All @@ -501,18 +504,22 @@ def predict_proba(self, X):

@available_if(_estimators_has("decision_function"))
def decision_function(self, X):
"""Returns the distance of each sample from the decision boundary for
each class. This can only be used with estimators which implement the
decision_function method.
"""Decision function for the OneVsRestClassifier.

Return the distance of each sample from the decision boundary for each
class. This can only be used with estimators which implement the
`decision_function` method.

Parameters
----------
X : array-like of shape (n_samples, n_features)
Input data.

Returns
-------
T : array-like of shape (n_samples, n_classes) or (n_samples,) for \
binary classification.
Result of calling `decision_function` on the final estimator.

.. versionchanged:: 0.19
output shape changed to ``(n_samples,)`` to conform to
Expand All @@ -527,11 +534,12 @@ def decision_function(self, X):

@property
def multilabel_(self):
"""Whether this is a multilabel classifier"""
"""Whether this is a multilabel classifier."""
return self.label_binarizer_.y_type_.startswith("multilabel")

@property
def n_classes_(self):
"""Number of classes."""
return len(self.classes_)

# TODO: Remove coef_ attribute in 1.1
Expand Down
0