From 653cbabf37f665cf1eef76bd8453b8782f77c0d0 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Sat, 15 Jul 2017 18:11:43 -0500 Subject: [PATCH] added examples to docstrings of LinearSVC and LinearSVR --- sklearn/svm/classes.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/sklearn/svm/classes.py b/sklearn/svm/classes.py index 4833042827361..7c6642a504ad1 100644 --- a/sklearn/svm/classes.py +++ b/sklearn/svm/classes.py @@ -108,6 +108,24 @@ class LinearSVC(BaseEstimator, LinearClassifierMixin, intercept_ : array, shape = [1] if n_classes == 2 else [n_classes] Constants in decision function. + Examples + -------- + >>> from sklearn.svm import LinearSVC + >>> from sklearn.datasets import make_classification + >>> X, y = make_classification(n_features=4, random_state=0) + >>> clf = LinearSVC(random_state=0) + >>> clf.fit(X, y) + LinearSVC(C=1.0, class_weight=None, dual=True, fit_intercept=True, + intercept_scaling=1, loss='squared_hinge', max_iter=1000, + multi_class='ovr', penalty='l2', random_state=0, tol=0.0001, + verbose=0) + >>> print(clf.coef_) + [[ 0.08551385 0.39414796 0.49847831 0.37513797]] + >>> print(clf.intercept_) + [ 0.28418066] + >>> print(clf.predict([[0, 0, 0, 0]])) + [1] + Notes ----- The underlying C implementation uses a random number generator to @@ -302,6 +320,22 @@ class LinearSVR(LinearModel, RegressorMixin): intercept_ : array, shape = [1] if n_classes == 2 else [n_classes] Constants in decision function. + Examples + -------- + >>> from sklearn.svm import LinearSVR + >>> from sklearn.datasets import make_regression + >>> X, y = make_regression(n_features=4, random_state=0) + >>> regr = LinearSVR(random_state=0) + >>> regr.fit(X, y) + LinearSVR(C=1.0, dual=True, epsilon=0.0, fit_intercept=True, + intercept_scaling=1.0, loss='epsilon_insensitive', max_iter=1000, + random_state=0, tol=0.0001, verbose=0) + >>> print(regr.coef_) + [ 16.35750999 26.91499923 42.30652207 60.47843124] + >>> print(regr.intercept_) + [-4.29756543] + >>> print(regr.predict([[0, 0, 0, 0]])) + [-4.29756543] See also --------