diff --git a/maint_tools/test_docstrings.py b/maint_tools/test_docstrings.py index df9a074c14c25..dce70247c5252 100644 --- a/maint_tools/test_docstrings.py +++ b/maint_tools/test_docstrings.py @@ -136,7 +136,6 @@ "RobustScaler", "SGDOneClassSVM", "SGDRegressor", - "SVC", "SVR", "SelectFdr", "SelectFpr", diff --git a/sklearn/svm/_base.py b/sklearn/svm/_base.py index 0e007276c0097..7aa15dadc003e 100644 --- a/sklearn/svm/_base.py +++ b/sklearn/svm/_base.py @@ -158,6 +158,7 @@ def fit(self, X, y, sample_weight=None): Returns ------- self : object + Fitted estimator. Notes ----- @@ -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") @@ -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: @@ -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 ------- @@ -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 diff --git a/sklearn/svm/_classes.py b/sklearn/svm/_classes.py index 3cf46d7efb860..309b9b48b4b67 100644 --- a/sklearn/svm/_classes.py +++ b/sklearn/svm/_classes.py @@ -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 @@ -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. @@ -707,6 +691,22 @@ class SVC(BaseSVC): .. [2] `Platt, John (1999). "Probabilistic outputs for support vector machines and comparison to regularizedlikelihood methods." `_ + + 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"