diff --git a/doc/modules/cross_validation.rst b/doc/modules/cross_validation.rst index 5bb98b3b4c0841f98af784a395849617c4fa8f2c..25f261592f2d528c7b6082a2d8e230eb32239908 100644 --- a/doc/modules/cross_validation.rst +++ b/doc/modules/cross_validation.rst @@ -40,7 +40,7 @@ data for testing (evaluating) our classifier:: >>> X_test.shape, y_test.shape ((60, 4), (60,)) - >>> clf = svm.SVC(kernel='linear', C=100).fit(X_train, y_train) + >>> clf = svm.SVC(kernel='linear', C=1).fit(X_train, y_train) >>> clf.score(X_test, y_test) # doctest: +ELLIPSIS 0.96... @@ -68,12 +68,12 @@ linear kernel Support Vector Machine on the iris dataset by splitting the data and fitting a model and computing the score 5 consecutive times (with different splits each time):: - >>> clf = svm.SVC(kernel='linear', C=100) + >>> clf = svm.SVC(kernel='linear', C=1) >>> scores = cross_validation.cross_val_score( ... clf, iris.data, iris.target, cv=5) ... >>> scores # doctest: +ELLIPSIS - array([ 1. ..., 0.96..., 0.9 ..., 0.96..., 1. ...]) + array([ 1. ..., 0.96..., 0.9 ..., 0.96..., 1. ]) The mean score and the standard deviation of the score estimate are hence given by:: @@ -89,7 +89,7 @@ scoring function, e.g. from the metrics module:: >>> cross_validation.cross_val_score(clf, iris.data, iris.target, cv=5, ... score_func=metrics.f1_score) ... # doctest: +ELLIPSIS - array([ 1. ..., 0.96..., 0.89..., 0.96..., 1. ...]) + array([ 1. ..., 0.96..., 0.89..., 0.96..., 1. ]) In the case of the Iris dataset, the samples are balanced across target classes hence the accuracy and the F1-score are almost equal. @@ -107,7 +107,7 @@ validation iterator instead, for instance:: >>> cross_validation.cross_val_score(clf, iris.data, iris.target, cv=cv) ... # doctest: +ELLIPSIS - array([ 0.97..., 1. , 1. ]) + array([ 0.97..., 0.97..., 1. ]) The available cross validation iterators are introduced in the following. diff --git a/doc/modules/feature_selection.rst b/doc/modules/feature_selection.rst index 6c0993733b9c9b47a3d39df6dcabf84ab0ea4e57..e4799a6b300fdd6fa6d147b31522508a83c875bb 100644 --- a/doc/modules/feature_selection.rst +++ b/doc/modules/feature_selection.rst @@ -97,7 +97,7 @@ for classification:: >>> X, y = iris.data, iris.target >>> X.shape (150, 4) - >>> X_new = LinearSVC(C=1., penalty="l1", dual=False).fit_transform(X, y) + >>> X_new = LinearSVC(C=0.01, penalty="l1", dual=False).fit_transform(X, y) >>> X_new.shape (150, 3) diff --git a/doc/modules/multiclass.rst b/doc/modules/multiclass.rst index ab0e8b9f301d7ce27db6852f95ba45398609233e..fd75ac1af3768508ae75d7ba42d54158427b13c3 100644 --- a/doc/modules/multiclass.rst +++ b/doc/modules/multiclass.rst @@ -64,7 +64,7 @@ default choice. Below is an example:: >>> from sklearn.svm import LinearSVC >>> iris = datasets.load_iris() >>> X, y = iris.data, iris.target - >>> OneVsRestClassifier(LinearSVC(C=100.)).fit(X, y).predict(X) + >>> OneVsRestClassifier(LinearSVC(C=1)).fit(X, y).predict(X) array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -110,7 +110,7 @@ dataset is used `n_classes` times. Below is an example:: >>> from sklearn.svm import LinearSVC >>> iris = datasets.load_iris() >>> X, y = iris.data, iris.target - >>> OneVsOneClassifier(LinearSVC(C=100.)).fit(X, y).predict(X) + >>> OneVsOneClassifier(LinearSVC(C=1)).fit(X, y).predict(X) array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -162,7 +162,7 @@ Example:: >>> from sklearn.svm import LinearSVC >>> iris = datasets.load_iris() >>> X, y = iris.data, iris.target - >>> OutputCodeClassifier(LinearSVC(C=100.), code_size=2, random_state=0).fit(X, y).predict(X) + >>> OutputCodeClassifier(LinearSVC(C=1), code_size=2, random_state=0).fit(X, y).predict(X) array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, diff --git a/doc/tutorial/basic/tutorial.rst b/doc/tutorial/basic/tutorial.rst index f708125e16ce8d573ccc716192e5ffcf34adaeb9..f26288cebb62ab9040b3063b6acc84b782a96682 100644 --- a/doc/tutorial/basic/tutorial.rst +++ b/doc/tutorial/basic/tutorial.rst @@ -167,8 +167,8 @@ one:: >>> clf.fit(digits.data[:-1], digits.target[:-1]) SVC(C=100.0, cache_size=200, class_weight=None, coef0=0.0, degree=3, - gamma=0.001, kernel='rbf', probability=False shrinking=True, tol=0.001, - verbose=False) + gamma=0.001, kernel='rbf', probability=False, shrinking=True, tol=0.001, + verbose=False) Now you can predict new values, in particular, we can ask to the classifier what is the digit of our last image in the `digits` dataset, @@ -204,9 +204,9 @@ persistence model, namely `pickle <http://docs.python.org/library/pickle.html>`_ >>> iris = datasets.load_iris() >>> X, y = iris.data, iris.target >>> clf.fit(X, y) - SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0, degree=3, - gamma=0.25, kernel='rbf', probability=False, shrinking=True, tol=0.001, - verbose=False) + SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0, degree=3, gamma=0.25, + kernel='rbf', probability=False, shrinking=True, tol=0.001, + verbose=False) >>> import pickle >>> s = pickle.dumps(clf) diff --git a/doc/tutorial/statistical_inference/model_selection.rst b/doc/tutorial/statistical_inference/model_selection.rst index 16513bd9916b06aac98313df1ac89369e96b73da..88c56aebcefab6e169442332ab270563e964bf1b 100644 --- a/doc/tutorial/statistical_inference/model_selection.rst +++ b/doc/tutorial/statistical_inference/model_selection.rst @@ -19,7 +19,7 @@ better**. >>> y_digits = digits.target >>> svc = svm.SVC(C=1, kernel='linear') >>> svc.fit(X_digits[:-100], y_digits[:-100]).score(X_digits[-100:], y_digits[-100:]) - 0.95999999999999996 + 0.97999999999999998 To get a better measure of prediction accuracy (which we can use as a proxy for goodness of fit of the model), we can successively split the @@ -39,7 +39,7 @@ data in *folds* that we use for training and testing:: ... y_train = np.concatenate(y_train) ... scores.append(svc.fit(X_train, y_train).score(X_test, y_test)) >>> print scores - [0.94156928213689484, 0.96661101836393992, 0.93322203672787984] + [0.93489148580968284, 0.95659432387312182, 0.93989983305509184] .. currentmodule:: sklearn.cross_validation @@ -69,13 +69,13 @@ The cross-validation can then be implemented easily:: >>> kfold = cross_validation.KFold(len(X_digits), k=3) >>> [svc.fit(X_digits[train], y_digits[train]).score(X_digits[test], y_digits[test]) ... for train, test in kfold] - [0.94156928213689484, 0.96661101836393992, 0.93322203672787984] + [0.93489148580968284, 0.95659432387312182, 0.93989983305509184] To compute the `score` method of an estimator, the sklearn exposes a helper function:: >>> cross_validation.cross_val_score(svc, X_digits, y_digits, cv=kfold, n_jobs=-1) - array([ 0.94156928, 0.96661102, 0.93322204]) + array([ 0.93489149, 0.95659432, 0.93989983]) `n_jobs=-1` means that the computation will be dispatched on all the CPUs of the computer. @@ -146,13 +146,13 @@ estimator during the construction and exposes an estimator API:: >>> clf.fit(X_digits[:1000], y_digits[:1000]) # doctest: +ELLIPSIS GridSearchCV(cv=None,... >>> clf.best_score_ - 0.98699897502292733 + 0.988991985997974 >>> clf.best_estimator_.gamma 9.9999999999999995e-07 >>> # Prediction performance on test set is not as good as on train set >>> clf.score(X_digits[1000:], y_digits[1000:]) - 0.94353826850690092 + 0.94228356336260977 By default the :class:`GridSearchCV` uses a 3-fold cross-validation. However, if @@ -164,7 +164,7 @@ a stratified 3-fold. :: >>> cross_validation.cross_val_score(clf, X_digits, y_digits) - array([ 0.98497496, 0.97829716, 0.97996661]) + array([ 0.97996661, 0.98163606, 0.98330551]) Two cross-validation loops are performed in parallel: one by the :class:`GridSearchCV` estimator to set `gamma`, the other one by diff --git a/doc/tutorial/statistical_inference/supervised_learning.rst b/doc/tutorial/statistical_inference/supervised_learning.rst index 08dc5d4d67ec612c5783ab0949117a123af7d034..b79d0d8ff7b08283a851fc99cb9c60e50212edd8 100644 --- a/doc/tutorial/statistical_inference/supervised_learning.rst +++ b/doc/tutorial/statistical_inference/supervised_learning.rst @@ -450,9 +450,9 @@ classification --:class:`SVC` (Support Vector Classification). >>> from sklearn import svm >>> svc = svm.SVC(kernel='linear') >>> svc.fit(iris_X_train, iris_y_train) - SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0, degree=3, - gamma=0.0, kernel='linear', probability=False, shrinking=True, tol=0.001, - verbose=False) + SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0, degree=3, gamma=0.0, + kernel='linear', probability=False, shrinking=True, tol=0.001, + verbose=False) .. warning:: **Normalizing data**