3
$\begingroup$

I'm wondering whether there is a difference between Linear SVM and SVM with a linear kernel. Or is a linear SVM just a SVM with a linear kernel?

If so, what is the difference between the two variables linear_svm and linear_kernel in the following code.

from sklearn import svm
linear_svm = svm.LinearSVC(C=1).fit(X_train, y_train)
linear_kernel_svm=svm.SVC(kernel='linear', C=1).fit(X_train, y_train)
$\endgroup$
2
$\begingroup$

As you can read in the documentation (http://scikit-learn.org/stable/modules/generated/sklearn.svm.LinearSVC.html) it's conceptually similar, but implemented in another way to add flexibility:

Similar to SVC with parameter kernel=’linear’, but implemented in terms of liblinear rather than libsvm, so it has more flexibility in the choice of penalties and loss functions and should scale better to large numbers of samples.

So if you only want to use linear support vectors use this one because it scales better and you get more freedom with your loss functions, but if you want to more easily try different kernels in a grid search use the more generic one.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thank you. but l get different accuracy : for linear_svm : 51.66 % and 21% for linear_kernel_svm, why ? $\endgroup$ – Joseph Nov 23 '17 at 10:26
  • $\begingroup$ Can you tell me a bit more about your problem? Is it multi-class? $\endgroup$ – Jan van der Vegt Nov 23 '17 at 10:28
  • $\begingroup$ Yes, it's a multi class problem (10 classes) for 200 examples (70 % training and 30 % test ) . Each example is 1-d vector of 2000 values. $\endgroup$ – Joseph Nov 23 '17 at 11:40
  • $\begingroup$ They handle multi-class problems in a different way, one of them treats it as a Class1-NotClass1 problem while the other one handles it as a Class1-Class2, Class1-Class3, Class2-Class3 etc problem. That might be the issue $\endgroup$ – Jan van der Vegt Nov 23 '17 at 11:59
  • $\begingroup$ It's a linearSVC that treats the problem as one vs all , and svm.SVC as class1 - not class 1 isn't it ? $\endgroup$ – Joseph Nov 23 '17 at 12:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.