Search code examples
pythonscikit-learnsvm

Sklearn built-in function for Hard margin SVM


I know that there is a built-in function for soft margin SVM as follows.

from sklearn.svm import SVC
clf = SVC(C=1, kernel = 'linear')
clf.fit(X, y)

But for Hard margin SVM, we need C=0, right? But the code report error ValueError: C <= 0 when I let C=0.


Solution

  • There is no hard-margin SVM in scikit-learn, as it is not very useful model. Numercically you can get very close to it by just setting C=1e10, but it might lead to convergence issues, as in dual formualtion of SVM C is an upper bound on the lagrange multipliers.