TL;DR
Forward stepwise selection starts with a model that has no predictors, only an intercept. At each step it tries every predictor not yet in the model, adds the one that reduces the residual error the most, and repeats. You stop when a score such as AIC, or validation error says the next addition is not worth it. The result is a nested sequence of models, each one a little bigger than the last.
Where you'll see it: choosing which of dozens of measured variables to keep in a regression, such as which genes, sensors or survey questions explain an outcome, when the full set of candidates is too large to fit all at once.
Intuition
Imagine you are packing a small bag from a shelf of forty items, and you want the bag to hold only what matters. You could try every combination, but there are about a trillion of them for forty items. Instead you grab the single most useful item first, then, with that in the bag, grab the next most useful one, and so on. You stop when the next item no longer earns its space.
That is forward stepwise selection. It is greedy: each step makes the best local choice and never goes back to revisit an earlier one. It is not guaranteed to find the best subset, but it finds a good one at a tiny fraction of the cost of checking every subset.
The cost difference matters. With candidate predictors, checking every subset means fitting models. Forward stepwise fits at most . For that is 820 fits against more than a trillion.
flowchart TD
A[Start: intercept only] --> B[Try each unused predictor]
B --> C[Add the one with the lowest residual error]
C --> D{Score still improving?}
D -- yes --> B
D -- no --> E[Keep the model with the best score]
The math
Let be the set of predictors currently in the model and the residual sum of squares (the sum of squared differences between observed and fitted responses) of the least-squares fit on , with the intercept always included. The rule at each step is
Adding a predictor never increases , so the training error alone would always say to add everything. The stopping rule is what does the work, and it is a choice from Model Selection: a held-out error, AIC, or Mallows' .
When the predictors are uncorrelated
The arithmetic simplifies when the centred predictors are mutually orthogonal, for . Then adding predictor to a model that already contains others reduces the residual sum of squares by exactly
Each predictor's contribution is independent of which others are already in, so the greedy path is simply the predictors ranked by . Real predictors are rarely orthogonal, but the toy case shows the mechanism cleanly.
Stopping with
For least squares, the full model with coefficients gives the noise estimate , and a submodel with coefficients has
Along the greedy path, pick the step with the smallest . This is the standard recipe, and Mallows Cp explains why a no-bias submodel has near .
- Start with (intercept only). Record .
- For each predictor , fit the regression on and record its RSS.
- Add the predictor with the smallest RSS to .
- Record the score (AIC, or validation error) for the new model.
- Repeat steps 2 to 4 until all predictors are in or the score stops improving for a set number of steps.
- Return the model along the path with the best score. Check it on a test set that did not drive the path.
Worked examples
We have observations and three centred predictors , , that are mutually orthogonal. The total sum of squares of the centred response is . Adding each predictor to the empty model reduces the RSS by:
- : reduction 60, so .
- : reduction 25, so .
- : reduction 0.5, so .
The greedy path is , then , then .
- Full model (all three predictors, with the intercept): .
- Model with and (): .
- Full model: . This is always exactly for the full model.
- Model with alone (): , far too high.
- The smallest is at , so the selected model is .
Interpretation: reduces the residual error by only 0.5, which is about 1.6 units of worth of fit for two units of penalty, so it does not earn its place. Dropping it costs nothing measurable on this data.
A dataset has 30 candidate predictors for a regression of hospital readmission times (not for clinical use). Forward stepwise selection adds predictors one at a time. Validation error on a held-out set falls for the first six additions, then rises slightly on the seventh and eighth.
- The validation error after six predictors is the lowest on the path.
- Predictors seven and eight each increased the fit on the training data but worsened validation error, the mark of overfitting.
- The team stops at six predictors and refits on training plus validation data.
- They report performance on a test set that was not used to build the path. Had they used the training error, the path would have kept growing until all thirty predictors were in, and the final model would have looked far better than it performs.
Interpretation: the stopping rule, not the greedy search, is what controls overfitting. The search only orders the predictors.
Tradeoffs and failure modes
| Situation | What goes wrong | Better choice |
|---|---|---|
| Two predictors are useful only together | Greedy never adds either, since each alone looks weak | Exhaustive search over small subsets, or regularised regression |
| Predictors are highly correlated | Greedy picks one of a near-duplicate pair at random, and the choice is unstable | Lasso Regression, or ridge with tuned strength |
| The path is used for inference | Reported p-values and confidence intervals ignore the selection step and look too narrow | Sample splitting, or treat the selected model as exploratory |
| Few candidates | Exhaustive search is affordable and finds the true best subset | Best-subset selection |
| Many candidates | Stepwise is fast but can overfit if the stopping rule is loose | Validation-based stopping, or L2 Regularization |
Forward stepwise is a search method, not a model-selection criterion. Its output is only as good as the score you stop with.
History
Stepwise procedures appeared in applied regression in the 1950s and 1960s, when computing an exact best subset was impractical and fitting even a few hundred regressions by hand or on early machines was slow. Greedy addition and deletion were the practical answer, and they spread through statistics textbooks and software because they were easy to run. Later work showed that the p-values reported after stepwise selection are misleading, because the procedure searched many models and then reported the winner as if it had been fixed in advance. Modern practice treats stepwise as a heuristic for ordering candidates and relies on held-out data or penalised methods to decide how many to keep.
Check yourself
QuestionRecall: why does forward stepwise need a stopping rule at all, when adding a predictor never increases the training residual sum of squares?Show answer
Because the training RSS can only fall or stay the same as predictors are added, so it always favours the largest model. A stopping rule such as validation error, AIC or penalises complexity or measures performance on data not used for fitting, which lets the procedure stop before it starts fitting noise.
QuestionComputation: with , adding alone gives RSS 30, adding alone gives RSS 45, and adding to the model with gives RSS 26. Which predictor does the greedy rule add first, and what is each step's reduction?Show answer
The first step adds , because its RSS of 30 is lower than 45; the reduction is . The second step adds and reduces RSS by . So is far more useful, and adds a small amount of fit. Whether it is worth keeping depends on whether exceeds the penalty of 2 for one more coefficient.
QuestionWhy: a greedy path misses a pair of predictors that together explain the response well but individually explain little. Explain the mechanism.Show answer
Greedy selection scores each candidate by how much it helps the current model. A predictor that is only useful in combination with another has a small marginal contribution when the partner is absent, so it ranks below predictors that look good alone. Once one partner is in, the other may become useful, but greedy may have already filled the model with other candidates, or the stopping rule may have halted first. The search never evaluates the pair jointly, which is why exhaustive or regularised methods can find what the greedy path misses.
QuestionApplied: a researcher uses forward stepwise on 200 candidate features, selects 12, then reports that the selected features each have p-values below 0.01. Why is that report misleading?Show answer
The p-values assume the 12 features were fixed before looking at the data. Stepwise chose them from 200 candidates using the same data, so the selection itself inflates apparent significance; some selected features would look significant under pure noise. The honest analysis either uses a separate dataset for the selection and the testing, or reports the result as exploratory and checks it on new data.
QuestionRecall: what does a value close to tell you about a submodel?Show answer
It suggests the submodel has little bias: on average its fit is about what the full model would give, after accounting for the penalty of 2 per coefficient. A well above means the submodel leaves out useful terms and is biased.