# What is the difference between Linear SVM and SVM with linear kernel?

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

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.

• Thank you. but l get different accuracy : for linear_svm : 51.66 % and 21% for linear_kernel_svm, why ? – Joseph Nov 23 '17 at 10:26
• Can you tell me a bit more about your problem? Is it multi-class? – Jan van der Vegt Nov 23 '17 at 10:28
• 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. – Joseph Nov 23 '17 at 11:40
• 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 – Jan van der Vegt Nov 23 '17 at 11:59
• It's a linearSVC that treats the problem as one vs all , and svm.SVC as class1 - not class 1 isn't it ? – Joseph Nov 23 '17 at 12:38