Machine LearningClassification Models & Kernels

What is a linear kernel?

A linear kernel is the simplest kernel used by a Support Vector Machine (SVM): it computes the dot product of two input vectors. Unlike nonlinear kernels, it does not introduce a nonlinear feature mapping; a linear SVM learns a straight-line boundary in two dimensions or a hyperplane in higher dimensions.

Formula

K(x, z) = x · z = x1*z1 + x2*z2 + ... + xn*zn

Here x and z are two feature vectors of the same length. A linear kernel measures their unnormalized dot-product similarity. It is not Euclidean distance or cosine similarity: vector magnitudes affect its value.

Simple numerical example

Take two vectors x = (2, 3) and z = (4, 1):

K(x, z) = 2*4 + 3*1
        = 8 + 3
        = 11

Nothing has been transformed into extra polynomial or radial features. The calculation uses the original inputs directly.

How does it classify?

With a linear kernel, an SVM learns a decision score:

f(x) = w · x + b
  • Positive score: one class.
  • Negative score: the other class.
  • Zero score: on the learned decision boundary.

Practical example: classify customer activity

Suppose two comparable-scale features summarize customer activity. We train on:

  • (1, 1) and (1, 2) → Inactive (0).
  • (4, 1) and (4, 2) → Active (1).

A maximum-margin linear boundary for this symmetric, separable dataset is x1 = 2.5:

  • New customer (2, 1) → Inactive (0).
  • New customer (3, 1) → Active (1).

The boundary is a straight line: this linear-kernel SVM cannot draw an arbitrary curved boundary on the supplied raw features.

Python example

PYTHON
from sklearn.svm import SVC X = [[1, 1], [1, 2], [4, 1], [4, 2]] y = [0, 0, 1, 1] model = SVC(kernel='linear', C=100) model.fit(X, y) print(model.predict([[2, 1], [3, 1]])) # [0 1] print(model.coef_) # approximately [[0.667, 0.0]] print(model.intercept_) # approximately [-1.667]

When should you use a linear kernel?

  • Try it first when the classes are reasonably separable in the supplied feature space, or when you need a simpler, more interpretable boundary.
  • It is often a strong choice for high-dimensional sparse features, such as bag-of-words text representations.
  • For large datasets, consider `LinearSVC`: it uses a specialized linear solver and often scales better than SVC(kernel='linear'). Their implementations, default loss functions, and multiclass handling differ, so their fitted results need not be identical.
  • Scale numerical features when appropriate, and select the regularization parameter C with validation data.

In short: a linear kernel computes K(x, z) = x · z and produces a linear SVM decision boundary. It is a practical baseline before considering RBF or polynomial kernels for nonlinear patterns.

References

#what is a linear kernel in SVM#linear kernel formula and example#linear kernel dot product SVM#SVC kernel linear vs LinearSVC#linear SVM decision boundary#machine-learning#classification#svm#linear-kernel#dot-product

Learning Sequence

Machine Learning Curriculum

67% Completed
Up NextMachine Learning

What is an RBF kernel?

Explore Related Questions

Deepen your understanding across related Machine Learning topics.

Machinoai Logo
Machinoai

Your edge in the AI era. Deep dives into machine learning concepts, paper explainers, verified industry jobs, and developer tools.

© 2026 Machinoai. All rights reserved.