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)

1 Answer 1


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.

  • $\begingroup$ Thank you. but l get different accuracy : for linear_svm : 51.66 % and 21% for linear_kernel_svm, why ? $\endgroup$
    – Joseph
    Nov 23, 2017 at 10:26
  • $\begingroup$ Can you tell me a bit more about your problem? Is it multi-class? $\endgroup$ Nov 23, 2017 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, 2017 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$ Nov 23, 2017 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, 2017 at 12:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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