FIX Correct the definition of gamma=scale in svm#13221
FIX Correct the definition of gamma=scale in svm#13221jnothman merged 7 commits intoscikit-learn:masterfrom qinhanmin2014:svm-gamma
scale in svm#13221Conversation
| "to False in version 0.22") | ||
| X, y = make_blobs(n_samples=54, random_state=0, centers=2) | ||
| grid = GridSearchCV(SVC(gamma='scale'), param_grid={'C': [1]}, cv=3) | ||
| grid = GridSearchCV(SVC(gamma='scale', random_state=0), |
There was a problem hiding this comment.
We do not always warn.
scikit-learn/sklearn/model_selection/_search.py
Lines 795 to 813 in d19a5dc
| for dataset in datasets: | ||
| for kernel in kernels: | ||
| clf = svm.SVC(gamma='scale', kernel=kernel, probability=True, | ||
| clf = svm.SVC(gamma=1, kernel=kernel, probability=True, |
There was a problem hiding this comment.
numerical issue here and below
X = np.array([[-2, -1], [-1, -1], [-1, -2], [1, 1], [1, 2], [2, 1]])
X_sp = sparse.lil_matrix(X)
Y = [1, 1, 1, 2, 2, 2]
clf = svm.SVC(gamma='scale', kernel=kernel, probability=True,
random_state=0, decision_function_shape='ovo')
sp_clf = svm.SVC(gamma='scale', kernel=kernel, probability=True,
random_state=0, decision_function_shape='ovo')
clf.fit(X, Y)
print(clf._gamma)
print(clf.support_)
sp_clf.fit(X_sp, Y)
print(sp_clf._gamma)
print(sp_clf.support_)
# 0.25
# [0 1 3 4]
# 0.25000000000000006
# [1 2 3 5]
| tol=0.001, verbose=False) | ||
| >>> clf.predict(X_test) | ||
| array([1, 0, 1, 1, 0]) | ||
| array([0, 0, 0, 1, 0]) |
There was a problem hiding this comment.
these samples are generated randomly (maybe we should avoid doing so in the tutorial?)
ogrisel
left a comment
There was a problem hiding this comment.
LGTM. But because gamma is now a fitted parameter, wouldn't it make sense to expose the estimated bandwidth as a public attribute gamma_ instead of a private attribute _gamma?
I would be +0 for making it public.
|
lgtm (but github doesn't let me click approve?) |
Will soon open a PR to update the tutorial.
Also +0 from my side and this is out of the scope of this PR. Maybe open an issue/PR if someone wants it? |
…arn#13221)" This reverts commit 7d8830d.
…arn#13221)" This reverts commit 7d8830d.
Closes #12741
See #13186 (comment):
And I'm wondering whether it's possible to solve #12741 in 0.20.3 by changing the definition of
gamma='scale'directly, since it's introduced erroneously in 0.20. This is an embarrassing mistake and I think it'll be much more difficult to solve it in 0.21.X (maybe at that time we'll need to deprecate scale and introduce another option).