TL;DR
A linear classifier answers a yes-or-no or which-class question by computing one weighted sum of an input's features, adding a bias, and checking the sign. The rule draws a flat boundary, a line in two dimensions and a plane or hyperplane in more, that splits the input space into two regions. It is the simplest useful classifier, and it is the building block of many larger models.
Builds on: Dot Product, Supervised Learning · Leads to: Support Vector Machine, Logistic Regression, Hinge Loss
Where it's used
Email spam filtering. Early spam filters counted features of each message, such as how often words like "free" appear and how many links it has. A weighted sum of those counts, compared against a threshold, gave a fast spam decision that could run on every message that arrived.
Medical screening scores. A clinic may combine a few measured values into one weighted score and flag patients above a cut-off for follow-up. Such scores are linear in their inputs, so they are linear classifiers. This is an illustration of the method, not medical advice, and any real score is validated on clinical data.
Fast first-pass tests in large systems. When a model must decide millions of times per second, a linear rule costs only one multiplication per feature. Teams often use it as a baseline that a heavier model must beat.
How it works
Take a single feature , a weight , and a bias . The rule is: predict "positive" when the score is above zero, and "negative" otherwise.
- Take the input . Suppose .
- Multiply by the weight: . The weight sets how strongly the feature pushes toward "positive".
- Add the bias: . The bias shifts the cut-off away from zero.
- Check the sign of the score. The score is positive, so predict "positive".
- Try . The score is . It is negative, so predict "negative".
- Find where the rule changes its answer. The score is zero at , so . Inputs above 2 are positive and inputs below 2 are negative. The single point is the boundary, the place where the score is zero.
- score = 2x - 4
- zero line
The same pipeline works with many features. The input is a list of numbers , the weights are a list of the same length, and the bias is one number .
flowchart LR
A["Features x"] --> B["Weighted sum w dot x"]
B --> C["Add bias b"]
C --> D{"Sign of score"}
D -- "positive" --> E["Class +1"]
D -- "negative" --> F["Class -1"]
The math
A linear classifier predicts a class from a score with
where is the weight vector, is the bias, is the dot product of the weights and the features, and is when is positive and when is negative.
Step 2 in symbols: the weighted sum
The dot product multiplies matching entries and adds them up. With and :
A large positive means that a large pushes the score up.
Step 6 in symbols: the boundary
The boundary is the set where the score is exactly zero:
In two dimensions this is a line. In three it is a plane. In dimensions it is a hyperplane, a flat set with one dimension fewer than the space it lives in. The weight vector is perpendicular to the boundary, so it points toward the positive side.
The distance from the boundary (beyond the walkthrough)
The distance from a point to the boundary is
where is the length of the weight vector. A point with a large absolute score that is far from the boundary is classified with more confidence. This distance is the quantity that a support vector machine tries to make as large as possible.
Worked examples
Use with and .
- For : .
- The score is positive, so the class is .
- For : .
- The score is negative, so the class is .
- The boundary is at , halfway between 1 and 3. Both points sit on opposite sides of it, as expected.
Use and , so the boundary is . Classify three points.
- Point : . Positive, so class .
- Point : . Negative, so class .
- Point : . The score is exactly zero, so the point lies on the boundary and the rule must pick a convention.
- Distance of from the boundary: .
- Interpretation: the rule is a diagonal line. Points above it are one class and points below it the other, and the point is comfortably on the positive side.
Suppose a spam filter has learned weights and bias for two features. The first feature is the count of the word "free", and the second is the number of links. Positive scores mean "spam".
- Email A: free , links . Score . Positive, so spam.
- Email B: free , links . Score . Negative, so not spam.
- Email C: free , links . Score . The score is zero, so it sits exactly on the boundary.
- Interpretation: the link count is worth twice as much as one use of the word "free" in this filter. Email C is the borderline case. A filter would send it to review, or use a tie-break rule.
- Note that the weights were chosen by training on labelled emails. Changing the cut-off by changing moves the boundary parallel to itself.
Try it: a classifier has and . Which class does receive? Answer: . The score is negative, so the class is .
Common mistakes and tradeoffs
"A linear classifier can separate any data if I train it long enough." It cannot. The classic counterexample is XOR: points and belong to one class, while and belong to the other. No single straight line puts the two pairs on opposite sides. Only data that is linearly separable, meaning a hyperplane exists that splits the classes exactly, can be perfectly classified this way. The 1969 book Perceptrons by Minsky and Papert made this limit famous.
"The weight vector is the boundary." It is not. The weight vector is perpendicular to the boundary. The boundary is the set of points where the score is zero, which is a flat set through the input space.
"A bigger score means a more certain answer." Only as a rough guide. The raw score grows with the length of , so scores are comparable only when is normalised. The distance formula in step 6 is the clean measure.
Tradeoff: simple and fast against limited shape. A linear classifier has only parameters, trains quickly, and is easy to read: each weight says how much a feature matters. The cost is a flat boundary. When classes form curved or interlocking regions, the classifier underfits, meaning it is too simple to capture the pattern even on its training data. Alternatives include decision trees for axis-aligned rules, kernel methods that bend the boundary, and multilayer networks that stack many linear pieces with non-linear functions between them.
When to use it. Use a linear classifier as a strong baseline, when the features are informative, when speed matters, or when you need to explain each decision. When not to use it. Avoid it when the classes interact in ways a straight cut cannot capture, such as XOR-like patterns in raw features.
History
In 1936 the statistician Ronald Fisher introduced a linear rule for separating two groups of measurements, now called linear discriminant analysis. In 1957 Frank Rosenblatt built the perceptron, an online learning rule that adjusts the weights after each mistake, and it was among the first models that learned a classifier from examples. Enthusiasm dropped after the 1969 critique of its limits to linearly separable data. The method returned as a core part of machine learning in the 1990s, when margin-based methods such as the support vector machine made linear classifiers both principled and powerful on high-dimensional data.
Recap
- A linear classifier computes a weighted sum of the features plus a bias and predicts the sign of that score.
- The boundary is where the score is zero: a line in two dimensions, a plane or hyperplane in more.
- The weight vector is perpendicular to the boundary, and the distance of a point from it is the absolute score divided by the length of the weights.
- A linear classifier works only when a hyperplane can separate the classes, which fails for XOR-like data.
- Read next: Support Vector Machine, which chooses the boundary with the widest margin; Logistic Regression, which turns the score into a probability; and Hinge Loss, the loss used to train margin-based linear classifiers.