Skip to content

Commit 28480f4

Browse files
glemaitrerth
authored andcommitted
DEP change the default of gamma in SVM (scikit-learn#13801)
1 parent ab3a1eb commit 28480f4

File tree

22 files changed

+183
-199
lines changed

22 files changed

+183
-199
lines changed

doc/modules/compose.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,12 @@ object::
216216
>>> from sklearn.datasets import load_digits
217217
>>> digits = load_digits()
218218
>>> pca1 = PCA()
219-
>>> svm1 = SVC(gamma='scale')
219+
>>> svm1 = SVC()
220220
>>> pipe = Pipeline([('reduce_dim', pca1), ('clf', svm1)])
221221
>>> pipe.fit(digits.data, digits.target)
222222
... # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
223223
Pipeline(memory=None,
224-
steps=[('reduce_dim', PCA(...)), ('clf', SVC(...))],
224+
steps=[('reduce_dim', PCA(...)), ('clf', SVC(...))],
225225
verbose=False)
226226
>>> # The pca instance can be inspected directly
227227
>>> print(pca1.components_) # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
@@ -238,7 +238,7 @@ object::
238238

239239
>>> cachedir = mkdtemp()
240240
>>> pca2 = PCA()
241-
>>> svm2 = SVC(gamma='scale')
241+
>>> svm2 = SVC()
242242
>>> cached_pipe = Pipeline([('reduce_dim', pca2), ('clf', svm2)],
243243
... memory=cachedir)
244244
>>> cached_pipe.fit(digits.data, digits.target)

doc/modules/ensemble.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ Vector Machine, a Decision Tree, and a K-nearest neighbor classifier::
947947
>>> # Training classifiers
948948
>>> clf1 = DecisionTreeClassifier(max_depth=4)
949949
>>> clf2 = KNeighborsClassifier(n_neighbors=7)
950-
>>> clf3 = SVC(gamma='scale', kernel='rbf', probability=True)
950+
>>> clf3 = SVC(kernel='rbf', probability=True)
951951
>>> eclf = VotingClassifier(estimators=[('dt', clf1), ('knn', clf2), ('svc', clf3)],
952952
... voting='soft', weights=[2, 1, 2])
953953

doc/modules/model_evaluation.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Usage examples:
100100
>>> from sklearn.model_selection import cross_val_score
101101
>>> iris = datasets.load_iris()
102102
>>> X, y = iris.data, iris.target
103-
>>> clf = svm.SVC(gamma='scale', random_state=0)
103+
>>> clf = svm.SVC(random_state=0)
104104
>>> cross_val_score(clf, X, y, scoring='recall_macro',
105105
... cv=5) # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
106106
array([0.96..., 0.96..., 0.96..., 0.93..., 1. ])
@@ -1964,7 +1964,7 @@ Next, let's compare the accuracy of ``SVC`` and ``most_frequent``::
19641964
We see that ``SVC`` doesn't do much better than a dummy classifier. Now, let's
19651965
change the kernel::
19661966

1967-
>>> clf = SVC(gamma='scale', kernel='rbf', C=1).fit(X_train, y_train)
1967+
>>> clf = SVC(kernel='rbf', C=1).fit(X_train, y_train)
19681968
>>> clf.score(X_test, y_test) # doctest: +ELLIPSIS
19691969
0.94...
19701970

doc/modules/model_persistence.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ persistence model, namely `pickle <https://docs.python.org/2/library/pickle.html
2323

2424
>>> from sklearn import svm
2525
>>> from sklearn import datasets
26-
>>> clf = svm.SVC(gamma='scale')
26+
>>> clf = svm.SVC()
2727
>>> iris = datasets.load_iris()
2828
>>> X, y = iris.data, iris.target
2929
>>> clf.fit(X, y) # doctest: +NORMALIZE_WHITESPACE

doc/modules/svm.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ n_features]`` holding the training samples, and an array y of class labels
7575
>>> from sklearn import svm
7676
>>> X = [[0, 0], [1, 1]]
7777
>>> y = [0, 1]
78-
>>> clf = svm.SVC(gamma='scale')
78+
>>> clf = svm.SVC()
7979
>>> clf.fit(X, y) # doctest: +NORMALIZE_WHITESPACE
8080
SVC(C=1.0, break_ties=False, cache_size=200, class_weight=None, coef0=0.0,
8181
decision_function_shape='ovr', degree=3, gamma='scale', kernel='rbf',
@@ -119,7 +119,7 @@ n_classes)``.
119119

120120
>>> X = [[0], [1], [2], [3]]
121121
>>> Y = [0, 1, 2, 3]
122-
>>> clf = svm.SVC(gamma='scale', decision_function_shape='ovo')
122+
>>> clf = svm.SVC(decision_function_shape='ovo')
123123
>>> clf.fit(X, Y) # doctest: +NORMALIZE_WHITESPACE
124124
SVC(C=1.0, break_ties=False, cache_size=200, class_weight=None, coef0=0.0,
125125
decision_function_shape='ovo', degree=3, gamma='scale', kernel='rbf',
@@ -314,8 +314,8 @@ Vector Regression depends only on a subset of the training data,
314314
because the cost function for building the model ignores any training
315315
data close to the model prediction.
316316

317-
There are three different implementations of Support Vector Regression:
318-
:class:`SVR`, :class:`NuSVR` and :class:`LinearSVR`. :class:`LinearSVR`
317+
There are three different implementations of Support Vector Regression:
318+
:class:`SVR`, :class:`NuSVR` and :class:`LinearSVR`. :class:`LinearSVR`
319319
provides a faster implementation than :class:`SVR` but only considers
320320
linear kernels, while :class:`NuSVR` implements a slightly different
321321
formulation than :class:`SVR` and :class:`LinearSVR`. See
@@ -331,7 +331,7 @@ floating point values instead of integer values::
331331
>>> clf = svm.SVR()
332332
>>> clf.fit(X, y) # doctest: +NORMALIZE_WHITESPACE
333333
SVR(C=1.0, cache_size=200, coef0=0.0, degree=3, epsilon=0.1,
334-
gamma='auto_deprecated', kernel='rbf', max_iter=-1, shrinking=True,
334+
gamma='scale', kernel='rbf', max_iter=-1, shrinking=True,
335335
tol=0.001, verbose=False)
336336
>>> clf.predict([[1, 1]])
337337
array([1.5])
@@ -349,7 +349,7 @@ Density estimation, novelty detection
349349
=======================================
350350

351351
The class :class:`OneClassSVM` implements a One-Class SVM which is used in
352-
outlier detection.
352+
outlier detection.
353353

354354
See :ref:`outlier_detection` for the description and usage of OneClassSVM.
355355

@@ -542,7 +542,7 @@ test vectors must be provided.
542542
>>> gram = np.dot(X, X.T)
543543
>>> clf.fit(gram, y) # doctest: +NORMALIZE_WHITESPACE
544544
SVC(C=1.0, break_ties=False, cache_size=200, class_weight=None, coef0=0.0,
545-
decision_function_shape='ovr', degree=3, gamma='auto_deprecated',
545+
decision_function_shape='ovr', degree=3, gamma='scale',
546546
kernel='precomputed', max_iter=-1,
547547
probability=False, random_state=None, shrinking=True, tol=0.001,
548548
verbose=False)

doc/tutorial/basic/tutorial.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ persistence model, `pickle <https://docs.python.org/2/library/pickle.html>`_::
216216

217217
>>> from sklearn import svm
218218
>>> from sklearn import datasets
219-
>>> clf = svm.SVC(gamma='scale')
219+
>>> clf = svm.SVC()
220220
>>> iris = datasets.load_iris()
221221
>>> X, y = iris.data, iris.target
222222
>>> clf.fit(X, y) # doctest: +NORMALIZE_WHITESPACE
@@ -291,7 +291,7 @@ maintained::
291291
>>> from sklearn import datasets
292292
>>> from sklearn.svm import SVC
293293
>>> iris = datasets.load_iris()
294-
>>> clf = SVC(gamma='scale')
294+
>>> clf = SVC()
295295
>>> clf.fit(iris.data, iris.target) # doctest: +NORMALIZE_WHITESPACE
296296
SVC(C=1.0, break_ties=False, cache_size=200, class_weight=None, coef0=0.0,
297297
decision_function_shape='ovr', degree=3, gamma='scale', kernel='rbf',
@@ -329,14 +329,14 @@ once will overwrite what was learned by any previous ``fit()``::
329329
>>> clf = SVC()
330330
>>> clf.set_params(kernel='linear').fit(X, y) # doctest: +NORMALIZE_WHITESPACE
331331
SVC(C=1.0, break_ties=False, cache_size=200, class_weight=None, coef0=0.0,
332-
decision_function_shape='ovr', degree=3, gamma='auto_deprecated',
332+
decision_function_shape='ovr', degree=3, gamma='scale',
333333
kernel='linear', max_iter=-1,
334334
probability=False, random_state=None, shrinking=True, tol=0.001,
335335
verbose=False)
336336
>>> clf.predict(X[:5])
337337
array([0, 0, 0, 0, 0])
338338

339-
>>> clf.set_params(kernel='rbf', gamma='scale').fit(X, y) # doctest: +NORMALIZE_WHITESPACE
339+
>>> clf.set_params(kernel='rbf').fit(X, y) # doctest: +NORMALIZE_WHITESPACE
340340
SVC(C=1.0, break_ties=False, cache_size=200, class_weight=None, coef0=0.0,
341341
decision_function_shape='ovr', degree=3, gamma='scale', kernel='rbf',
342342
max_iter=-1, probability=False,
@@ -363,8 +363,7 @@ the target data fit upon::
363363
>>> X = [[1, 2], [2, 4], [4, 5], [3, 2], [3, 1]]
364364
>>> y = [0, 0, 1, 1, 2]
365365

366-
>>> classif = OneVsRestClassifier(estimator=SVC(gamma='scale',
367-
... random_state=0))
366+
>>> classif = OneVsRestClassifier(estimator=SVC(random_state=0))
368367
>>> classif.fit(X, y).predict(X)
369368
array([0, 0, 1, 1, 2])
370369

doc/tutorial/statistical_inference/supervised_learning.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ classification --:class:`SVC` (Support Vector Classification).
463463
>>> svc = svm.SVC(kernel='linear')
464464
>>> svc.fit(iris_X_train, iris_y_train) # doctest: +NORMALIZE_WHITESPACE
465465
SVC(C=1.0, break_ties=False, cache_size=200, class_weight=None, coef0=0.0,
466-
decision_function_shape='ovr', degree=3, gamma='auto_deprecated',
466+
decision_function_shape='ovr', degree=3, gamma='scale',
467467
kernel='linear', max_iter=-1,
468468
probability=False, random_state=None, shrinking=True, tol=0.001,
469469
verbose=False)

examples/preprocessing/plot_discretization_classification.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def get_name(estimator):
8383
(GradientBoostingClassifier(n_estimators=50, random_state=0), {
8484
'learning_rate': np.logspace(-4, 0, 10)
8585
}),
86-
(SVC(random_state=0, gamma='scale'), {
86+
(SVC(random_state=0), {
8787
'C': np.logspace(-2, 7, 10)
8888
}),
8989
]

sklearn/ensemble/tests/test_bagging.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_classification():
7171
Perceptron(tol=1e-3),
7272
DecisionTreeClassifier(),
7373
KNeighborsClassifier(),
74-
SVC(gamma="scale")]:
74+
SVC()]:
7575
for params in grid:
7676
BaggingClassifier(base_estimator=base_estimator,
7777
random_state=rng,
@@ -117,17 +117,15 @@ def fit(self, X, y):
117117
for f in ['predict', 'predict_proba', 'predict_log_proba', 'decision_function']:
118118
# Trained on sparse format
119119
sparse_classifier = BaggingClassifier(
120-
base_estimator=CustomSVC(gamma='scale',
121-
decision_function_shape='ovr'),
120+
base_estimator=CustomSVC(decision_function_shape='ovr'),
122121
random_state=1,
123122
**params
124123
).fit(X_train_sparse, y_train)
125124
sparse_results = getattr(sparse_classifier, f)(X_test_sparse)
126125

127126
# Trained on dense format
128127
dense_classifier = BaggingClassifier(
129-
base_estimator=CustomSVC(gamma='scale',
130-
decision_function_shape='ovr'),
128+
base_estimator=CustomSVC(decision_function_shape='ovr'),
131129
random_state=1,
132130
**params
133131
).fit(X_train, y_train)
@@ -155,7 +153,7 @@ def test_regression():
155153
DummyRegressor(),
156154
DecisionTreeRegressor(),
157155
KNeighborsRegressor(),
158-
SVR(gamma='scale')]:
156+
SVR()]:
159157
for params in grid:
160158
BaggingRegressor(base_estimator=base_estimator,
161159
random_state=rng,
@@ -201,15 +199,15 @@ def fit(self, X, y):
201199

202200
# Trained on sparse format
203201
sparse_classifier = BaggingRegressor(
204-
base_estimator=CustomSVR(gamma='scale'),
202+
base_estimator=CustomSVR(),
205203
random_state=1,
206204
**params
207205
).fit(X_train_sparse, y_train)
208206
sparse_results = sparse_classifier.predict(X_test_sparse)
209207

210208
# Trained on dense format
211209
dense_results = BaggingRegressor(
212-
base_estimator=CustomSVR(gamma='scale'),
210+
base_estimator=CustomSVR(),
213211
random_state=1,
214212
**params
215213
).fit(X_train, y_train).predict(X_test)
@@ -334,7 +332,7 @@ def test_oob_score_classification():
334332
iris.target,
335333
random_state=rng)
336334

337-
for base_estimator in [DecisionTreeClassifier(), SVC(gamma="scale")]:
335+
for base_estimator in [DecisionTreeClassifier(), SVC()]:
338336
clf = BaggingClassifier(base_estimator=base_estimator,
339337
n_estimators=100,
340338
bootstrap=True,
@@ -464,8 +462,7 @@ def test_parallel_classification():
464462
assert_array_almost_equal(y1, y3)
465463

466464
# decision_function
467-
ensemble = BaggingClassifier(SVC(gamma='scale',
468-
decision_function_shape='ovr'),
465+
ensemble = BaggingClassifier(SVC(decision_function_shape='ovr'),
469466
n_jobs=3,
470467
random_state=0).fit(X_train, y_train)
471468

@@ -482,8 +479,7 @@ def test_parallel_classification():
482479
"".format(X_test.shape[1], X_err.shape[1]),
483480
ensemble.decision_function, X_err)
484481

485-
ensemble = BaggingClassifier(SVC(gamma='scale',
486-
decision_function_shape='ovr'),
482+
ensemble = BaggingClassifier(SVC(decision_function_shape='ovr'),
487483
n_jobs=1,
488484
random_state=0).fit(X_train, y_train)
489485

@@ -529,7 +525,7 @@ def test_gridsearch():
529525
parameters = {'n_estimators': (1, 2),
530526
'base_estimator__C': (1, 2)}
531527

532-
GridSearchCV(BaggingClassifier(SVC(gamma="scale")),
528+
GridSearchCV(BaggingClassifier(SVC()),
533529
parameters,
534530
scoring="roc_auc").fit(X, y)
535531

@@ -578,7 +574,7 @@ def test_base_estimator():
578574

579575
assert isinstance(ensemble.base_estimator_, DecisionTreeRegressor)
580576

581-
ensemble = BaggingRegressor(SVR(gamma='scale'),
577+
ensemble = BaggingRegressor(SVR(),
582578
n_jobs=3,
583579
random_state=0).fit(X_train, y_train)
584580
assert isinstance(ensemble.base_estimator_, SVR)

sklearn/ensemble/tests/test_voting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def test_sample_weight():
325325
"""Tests sample_weight parameter of VotingClassifier"""
326326
clf1 = LogisticRegression(random_state=123)
327327
clf2 = RandomForestClassifier(random_state=123)
328-
clf3 = SVC(gamma='scale', probability=True, random_state=123)
328+
clf3 = SVC(probability=True, random_state=123)
329329
eclf1 = VotingClassifier(estimators=[
330330
('lr', clf1), ('rf', clf2), ('svc', clf3)],
331331
voting='soft').fit(X, y, sample_weight=np.ones((len(y),)))

0 commit comments

Comments
 (0)