Feature Representation and Model Choice
Linear models can only model linear relationships, so with one feature their fitted form is a line.
Two Models, One Wavy Feature
Imagine you have a single continuous input feature and a continuous output that rises and falls as the feature changes. You want to fit two different regression models to the same training points and then draw both predictions on top of those points. One model is a linear regression, and the other is a decision tree regressor. Before reading any explanation, make a prediction: which of the two curves will follow the training points more closely, and why?
The source frames this as a small experiment. The data is the wave regression dataset from Chapter 2, which has only one input feature. The plot you produce compares the two prediction curves over the training points. Your task is to read the plot and identify where each curve sits relative to the points. Memorizing the output is not the goal. The goal is to understand why the two curves look the way they do.
Tracing the Linear Model's Shape
A linear model is limited by its form. When there is a single input feature, the relationship between input and output is a line. A line has exactly two numbers that you can choose: one slope and one intercept. No choice of those two numbers can make the line curve up and down to chase a wavy pattern. So the linear regression curve in this comparison is a straight line, even when the training points clearly bend.
Trace the state of this model step by step. Start with the training points, which form a curved cloud. The linear model then searches only among straight lines, so its final state is one slope and one intercept. Whatever the points do, the prediction has to stay on that single line across the whole input range.
This limitation belongs to the model family, not to a bad fit. A linear model that looks poor on wavy data is doing exactly what it was built to do. When you see a straight prediction line cutting through a curved cloud of points, the first explanation to consider is the model's form, before you blame the code or the data.
How a Decision Tree Divides the Input Range
A decision tree regressor does not have a fixed functional form like a line. Instead, it builds its prediction by making a sequence of splits on the input feature. Each split cuts the range of the feature into regions, and the tree assigns an output value to each region. Because the prediction is built region by region, the tree can follow bends and irregular patterns that a single straight line cannot.
Follow the state as the tree is built. At the start there is one region covering the whole feature range. The first split divides that range in two. Each further split divides one of the existing regions again. The final state is a set of intervals along the feature axis, and each interval carries a single output value. Plotted together, those values form a stepped, piecewise-constant curve rather than a smooth line.
Binning: One Feature Becomes Several
Binning, also called discretization, splits one continuous feature into multiple features. The source presents it as one way to make a linear model more powerful on continuous data. You choose a set of edges along the feature's range. Each resulting interval is a bin. Each sample is then represented by indicator features that record which bin its value falls into, with a 1 for the bin it belongs to and a 0 for the others.
The key change is what the linear model receives. A linear model still produces a line in the features it is given. When the single continuous feature is replaced by several derived indicator features, the model is no longer restricted to one slope across the entire input range. Each indicator feature can carry its own weight. The combined prediction can therefore rise and fall in different regions, producing a stepped curve. The model is still linear, but the representation of the data has changed.
Binning one value into indicator features
A continuous feature ranges from 0 to 10. Split it into four bins using the edges 0, 2.5, 5, 7.5, and 10. Show how a single sample with value 6.1 is represented after binning.
- 1Choose the edges
The edges 0, 2.5, 5, 7.5, and 10 define four intervals: 0 to 2.5, 2.5 to 5, 5 to 7.5, and 7.5 to 10.
- 2Locate the value
The value 6.1 is larger than 5 and smaller than 7.5, so it falls in the third bin.
- 3Write the indicator features
Each bin becomes one column. The third column is 1 and the other three columns are 0, so the sample becomes 0, 0, 1, 0.
- 4Check what the model sees
The linear model now receives four columns instead of the raw value 6.1. Only the bin membership is visible to it.
The single continuous value 6.1 is represented as the indicator vector 0, 0, 1, 0. A linear model can give each of the four columns its own weight.
Notice what this illustration shows and what it hides. The original value is replaced by indicator features that record which range it falls in. After this change, only the bins are visible to the linear model, not the raw values. The model can no longer see how far a sample sits inside its bin, only which bin it is in.
Why Representation Decides the Result
The source is careful about one qualification. A decision tree's ability to capture complex patterns depends strongly on how the data is represented. The same tree can look powerful or weak depending on the feature representation it receives. So the central question is not only which model is more capable. The question is how each model consumes the feature it is given.
Following the Pipeline When a Result Surprises You
When a model comparison gives a result you did not expect, the source recommends working through the pipeline in order instead of guessing. The check runs in three stages. Start with the feature representation: how many input features are there, and are they continuous as given or transformed? Next, identify the model family and what shape it can express. Only then compare the predicted curves with the training points. The first point where your expectation and your reasoning disagree tells you where to look.
Two models are fitted to the same single continuous feature. The linear model's curve is a straight line that misses a clear wavy pattern in the points, and the tree's curve follows the pattern closely. Using the three-stage check, name the stage where you would look first for the cause of the surprise, and explain why.
Hints
- Ask first how many features the linear model received and whether they were continuous or transformed.
- A line cannot bend, so consider whether the form of the model explains the miss before suspecting the code or the data.
Mistakes Learners Make with Representation
Common mistake Blaming the code or the data when a linear fit looks poor on wavy points
Why it failsA straight line cannot curve up and down, so a poor fit on a curved pattern is the expected behavior of a linear model with one feature.
Do this insteadCheck the model's form first. A line can only have one slope and one intercept.
Common mistake Assuming the decision tree is more capable in every situation
Why it failsThe source says the tree's ability to capture complex patterns depends strongly on how the data is represented.
Do this insteadAsk how each model consumes the feature it is given, not just which model is more capable.
Common mistake Thinking binning leaves the linear model unchanged
Why it failsAfter binning, the model receives several indicator features instead of one continuous value, so it can assign different weights to different ranges.
Do this insteadRemember that the model is still linear in the features it receives, but the representation of the data has changed.
Common mistake Reading the stepped curve of a binned model as a smooth function of the raw value
Common mistake Comparing fitted curves before checking the feature representation and the model family
Key Takeaways
- A linear model with one continuous feature is restricted to a straight line, because a line has only one slope and one intercept, so a poor fit on wavy data reflects the model's form.
- A decision tree regressor builds its prediction from a sequence of splits, assigning an output value to each region, which lets it follow bends a single line cannot.
- Binning, also called discretization, replaces one continuous feature with several indicator features, letting a linear model assign different weights to different ranges and produce a stepped curve.
- The strength of a decision tree depends strongly on how the data is represented, so check the feature representation first, then the model family, then the fitted curves when a result surprises you.