Skip to content

Commit

Permalink
DOC Ensures that SVC passes numpydoc validation (#20457)
Browse files Browse the repository at this point in the history
Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
  • Loading branch information
jmloyola and glemaitre authored Jul 13, 2021
1 parent 67eb690 commit 9c2b3b6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
1 change: 0 additions & 1 deletion maint_tools/test_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@
"RobustScaler",
"SGDOneClassSVM",
"SGDRegressor",
"SVC",
"SVR",
"SelectFdr",
"SelectFpr",
Expand Down
23 changes: 22 additions & 1 deletion sklearn/svm/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def fit(self, X, y, sample_weight=None):
Returns
-------
self : object
Fitted estimator.
Notes
-----
Expand Down Expand Up @@ -617,6 +618,12 @@ def _validate_for_predict(self, X):

@property
def coef_(self):
"""Weights assigned to the features when `kernel="linear"`.
Returns
-------
ndarray of shape (n_features, n_classes)
"""
if self.kernel != "linear":
raise AttributeError("coef_ is only available when using a linear kernel")

Expand All @@ -637,6 +644,7 @@ def _get_coef(self):

@property
def n_support_(self):
"""Number of support vectors for each class."""
try:
check_is_fitted(self)
except NotFittedError:
Expand Down Expand Up @@ -710,11 +718,12 @@ def _validate_targets(self, y):
return np.asarray(y, dtype=np.float64, order="C")

def decision_function(self, X):
"""Evaluates the decision function for the samples in X.
"""Evaluate the decision function for the samples in X.
Parameters
----------
X : array-like of shape (n_samples, n_features)
The input samples.
Returns
-------
Expand Down Expand Up @@ -940,10 +949,22 @@ def _get_coef(self):

@property
def probA_(self):
"""Parameter learned in Platt scaling when `probability=True`.
Returns
-------
ndarray of shape (n_classes * (n_classes - 1) / 2)
"""
return self._probA

@property
def probB_(self):
"""Parameter learned in Platt scaling when `probability=True`.
Returns
-------
ndarray of shape (n_classes * (n_classes - 1) / 2)
"""
return self._probB


Expand Down
34 changes: 17 additions & 17 deletions sklearn/svm/_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ class SVC(BaseSVC):
weight one.
The "balanced" mode uses the values of y to automatically adjust
weights inversely proportional to class frequencies in the input data
as ``n_samples / (n_classes * np.bincount(y))``
as ``n_samples / (n_classes * np.bincount(y))``.
verbose : bool, default=False
Enable verbose output. Note that this setting takes advantage of a
Expand Down Expand Up @@ -675,22 +675,6 @@ class SVC(BaseSVC):
shape_fit_ : tuple of int of shape (n_dimensions_of_X,)
Array dimensions of training vector ``X``.
Examples
--------
>>> import numpy as np
>>> from sklearn.pipeline import make_pipeline
>>> from sklearn.preprocessing import StandardScaler
>>> X = np.array([[-1, -1], [-2, -1], [1, 1], [2, 1]])
>>> y = np.array([1, 1, 2, 2])
>>> from sklearn.svm import SVC
>>> clf = make_pipeline(StandardScaler(), SVC(gamma='auto'))
>>> clf.fit(X, y)
Pipeline(steps=[('standardscaler', StandardScaler()),
('svc', SVC(gamma='auto'))])
>>> print(clf.predict([[-0.8, -1]]))
[1]
See Also
--------
SVR : Support Vector Machine for Regression implemented using libsvm.
Expand All @@ -707,6 +691,22 @@ class SVC(BaseSVC):
.. [2] `Platt, John (1999). "Probabilistic outputs for support vector
machines and comparison to regularizedlikelihood methods."
<http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.41.1639>`_
Examples
--------
>>> import numpy as np
>>> from sklearn.pipeline import make_pipeline
>>> from sklearn.preprocessing import StandardScaler
>>> X = np.array([[-1, -1], [-2, -1], [1, 1], [2, 1]])
>>> y = np.array([1, 1, 2, 2])
>>> from sklearn.svm import SVC
>>> clf = make_pipeline(StandardScaler(), SVC(gamma='auto'))
>>> clf.fit(X, y)
Pipeline(steps=[('standardscaler', StandardScaler()),
('svc', SVC(gamma='auto'))])
>>> print(clf.predict([[-0.8, -1]]))
[1]
"""

_impl = "c_svc"
Expand Down

0 comments on commit 9c2b3b6

Please sign in to comment.