0PricingLogin
Learn AI with Python · Lesson

SVMs for Classification with sklearn

SVC, LinearSVC, kernel selection, class_weight='balanced', probability=True.

SVMs in scikit-learn

scikit-learn offers several SVM classifiers. The main one is SVC, which supports linear and kernel boundaries through its kernel parameter.

from sklearn.svm import SVC

model = SVC(kernel="rbf", C=1.0, gamma="scale")
model.fit(Xtr, ytr)
print(model.score(Xte, yte))

The Core SVC Parameters

Three parameters drive SVC behavior:

  • kernel the boundary type (linear, rbf, poly)
  • C the error penalty / regularization
  • gamma the kernel width for rbf/poly
from sklearn.svm import SVC

model = SVC(kernel="rbf", C=10, gamma=0.1)

All lessons in this course

  1. SVM Theory: Margins and Support Vectors
  2. Kernel Trick: RBF, Polynomial, and Sigmoid
  3. SVMs for Classification with sklearn
  4. SVMs for Regression (SVR)
← Back to Learn AI with Python