Prestyy
Prestyy

Reputation: 103

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

equation.

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,) e.g. [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?

Upvotes: 7

Views: 7142

Answers (1)

KRKirov
KRKirov

Reputation: 4004

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

Upvotes: 5

Related Questions