简体   繁体   中英

Default value of gamma SVC sklearn

I'm using SVC from sklearn.svm for binary classification in python. For the gamma parameter it says that it's default value is

方程 .

I'm having a hard time understading this. Can you tell me what's the default value of gamma ,if for example, the input is a vector of 3 dimensions(3,) eg [3,3,3] and the number of input vectors are 10.000? Also, is there a way i can print it out to see its value?

This is easy to see with an example. The array X below has two features (columns). The variance of the array is 1.75. The default gamma is therefore is 1/(2*1.75) = 0.2857. You can verify this by checking the ._gamma attribute of the classifier.

import numpy as np
from sklearn.svm import SVC

X = np.array([[-1, -1], [-2, -1], [1, 1], [2, 1]])
y = np.array([1, 1, 2, 2])

clf = SVC(gamma='scale')
clf.fit(X, y)

n_features = X.shape[1]
gamma = 1 / (n_features * X.var())

clf._gamma

Output: X

Out[24]: 
array([[-1, -1],
       [-2, -1],
       [ 1,  1],
       [ 2,  1]])

n_features
Out[25]: 2

X.var()
Out[26]: 1.75

gamma
Out[27]: 0.2857142857142857

clf._gamma
Out[28]: 0.2857142857142857

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM