- A linear classifier can only draw a straight boundary in its input space.
- A feature map sends each input to a new set of coordinates.
- A linear boundary in the new space can be a curve in the original space.
This lesson follows Classification & Logistic Regression. For the geometry of coordinates, see Linear Algebra.
1. A ring of points
Imagine two classes arranged as rings: class 1 is inside, class 0 is outside. A straight line cannot separate them. Wherever you place the line, one class wraps around the other.
A logistic regression model with inputs (x, y) can only produce a line. More training will not bend it. The problem is not the optimizer; it is the shape of the model.
2. Add a feature
For a ring, distance from the centre matters more than the individual coordinates. Define one new feature:
The feature map is φ(x, y) = x² + y². It sends a two-dimensional point to a single number. Inner points get small values; outer points get large values.
In the new one-dimensional feature, the classes are two clusters. A threshold at r² = 1.5 separates them. That threshold is a linear boundary in feature space.
3. The model in feature space
A logistic model on the new feature still computes a score and a sigmoid. If the feature is r², the boundary is:
Back in the original plane, that equation is a circle:
A circle is not a line. The model is still linear in its parameter; the nonlinearity came from the feature map. This is the central trick of feature-based learning.
With more than one feature, a linear score can combine them:
4. A worked example
Worked example: map four points and apply a threshold
Use φ(x, y) = x² + y² and a threshold of 1.5. Points with r² > 1.5 are classified as outer (class 0); points below are inner (class 1).
| point | r² = x² + y² | side of threshold | class |
|---|---|---|---|
| (0.5, 0) | 0.25 | below | inner (1) |
| (0.7, 0.4) | 0.65 | below | inner (1) |
| (2, 0) | 4.00 | above | outer (0) |
| (1.8, 1.2) | 4.68 | above | outer (0) |
The threshold corresponds to the circle r² = 1.5, or r ≈ 1.225. The decision boundary is curved in the original space, but it is a single cut in the feature space.
Notice that the feature map did not add a new model class; it changed the representation. A linear model in the new feature is still a linear model, with a different meaning of “linear.”
5. More features
The radius is one hand-chosen feature. A systematic alternative is a polynomial basis. In two dimensions, the complete degree-two basis is:
It includes the interaction term x₁x₂, which can create saddles and rotated boundaries. The number of features grows quickly with degree:
For two input dimensions, degree 1 gives 2 features, degree 2 gives 5, and degree 3 gives 9 (without the bias term). The decision-boundary playground uses a smaller quadratic map:
That is four features: x, y, x², y². It can draw circles and ellipses but not the rotated saddle that x·y would allow.
6. Where this fails
A feature map is a choice. If you choose the wrong features, the boundary is still wrong. A high-degree polynomial can fit almost any training set, including its noise, and then fail on new points. More features increase the risk of overfitting; they do not automatically increase understanding.
The number of features also explodes. A full degree-3 basis in 10 dimensions has hundreds of terms. Deep networks avoid hand-listing every product by learning the representation itself.
The next question is how to tell whether a flexible boundary is learning the pattern or memorizing the examples. That is the overfitting question, and it applies to every model in this track.
7. Going deeper
The key identity is simple: a linear function of φ(x) is a nonlinear function of x whenever φ is nonlinear. The model class is still “linear in the parameters,” which is why the same logistic regression code works after the feature map.
A kernel method takes this further: it computes inner products in a high-dimensional feature space without explicitly listing every feature. That is how an SVM can draw a curved boundary while solving a linear problem in a lifted space. Support vector machines are outside this phase, but the idea is the same.
Deep learning goes one step further and learns φ from data. The final layer may still be linear; the layers before it build the representation. That is why a neural network can replace hand-crafted feature maps with learned ones.
8. Practice
Map the point (0, 2) with φ(x, y) = x² + y². Is it inside or outside the threshold 1.5?
Why can a linear classifier in the original (x, y) space not separate the two rings, no matter how long you train?
How many features are in the full degree-2 polynomial basis for two inputs, excluding the bias?
9. Resources
The MIT chapter shows the 1D quadratic example, the XOR basis, and radial basis functions. The Crash Course covers feature engineering and polynomial features in a practical setting. Both links were opened and checked for this lesson.
Continue the track
Open the playground for this topic
Decision Boundary Playground →Add and drag points, switch between linear, quadratic, and neural models, and watch the boundary and both accuracy scores respond.
Next on the recommended path
Neural Networks →The mathematics behind this topic: Linear algebra.