Feature selection
Intermediate
What you need first. Nothing else on this path comes first. This page is part of Statistical learning.
In statistical learning, feature selection is the choice of which measured predictors enter a fitted model, with the others left out. A regression that is handed every recorded measurement will give each of them a coefficient. Some of those measurements have nothing to do with the response. Feature selection, also called variable selection, is the decision to leave those measurements out, so that the fitted model uses only a subset of the predictors.[1] [2]
Feature selection
| Fact | Value |
|---|---|
| Topic | Statistical learning |
| Listed on | Statistical learning |
| Worked example | 1 |
Motivating example
Three cases have predictors and response equal to , and . An intercept-only fit predicts the mean every time, and its residual sum of squares is . A straight line in alone, still with an intercept, has residual sum of squares . The line passes through all three points, so the residual sum of squares for alone is . The variable that earns its place is . Keeping as well cannot make the training residual sum of squares smaller than , and it adds a coefficient that the three points do not need.[1]
Definition
For the linear model
feature selection means choosing a subset of and fitting the model on that subset. The excluded predictors are absent. Their coefficients are not estimated, which is the same end state as a coefficient fixed at zero.[1] [2]
Subset selection does the choice first and then applies least squares to the survivors. Best-subset selection, for each size , finds the subset of predictors with the smallest residual sum of squares. Forward stepwise selection starts from the intercept and adds, one predictor at a time, the variable that most improves the fit. Backward stepwise selection starts from the full model and deletes the predictor with the least effect on the fit. Shrinkage can do the same job inside one fit: an penalty, as in the lasso, drives some coefficients to exact zeros when the penalty is large enough, and those zeros are the excluded variables.[1] [2]
The same idea is not limited to least squares. For logistic regression the residual sum of squares is replaced by the deviance, and an penalty on the logistic coefficients again sets some of them to zero. A quadratic penalty does not. Linear discriminant analysis, ordinary logistic regression, and the support-vector classifier, regularised by a square penalty, give every feature a nonzero weight.[1] [2]
Interpretation
Least squares with many predictors has two familiar failures. When the number of predictors is not small relative to the sample, the fitted coefficients move a lot from sample to sample, and predictions on new cases suffer. And a coefficient that is only a little different from zero is still a number one has to explain. Setting the useless coefficients to zero, or never estimating them, buys a simpler equation. The price is bias: a predictor that was wrongly dropped cannot help. The useful procedures are the ones that make that exchange on purpose, and that do not decide it by training error alone.[1] [2]
Training residual sum of squares for the best subset of each size cannot rise as the size increases: the larger search includes every smaller subset. On the three cases above, the best residual sums of squares are at size , at size , and at size . Training moves the other way. A rule that picks the subset with the smallest training residual sum of squares therefore has no reason to stop before every predictor is available, and here it cannot prefer to .[1] [2]
The search itself has a cost that grows with . Best subset selection considers subsets. At that is fits. Forward stepwise fits the null model and then candidates at step , which is models in all, or models when . Forward stepwise can still miss the best subset of a given size. If the best single predictor is and the best pair is , the forward path has already committed to and cannot reach that pair. The narrower path is also the statistical point of the shortcut: a search through every subset pays in variance for the subset that looked best on the training sample.[1] [2]
Ridge regression shrinks coefficients and does not set them to zero, except in the limit of an infinite penalty, where every coefficient is zero. The lasso penalty does set coefficients to zero for large enough , so the fitted equation names the variables it kept. When there are more predictors than observations, a lasso solution has at most as many nonzero coefficients as there are observations.[1] [2]
Use a selection procedure when the scientific or practical product is a short list of predictors, or when is large enough that an unpenalised least-squares fit is noisy. Best subset selection is feasible for up to about or . Beyond that, forward stepwise, or the lasso, is the computation one can actually run. Backward stepwise needs more observations than predictors, because it starts from the full least-squares fit. Forward stepwise does not.[2] [1]
The size of the subset, or the lasso penalty, is not chosen by the training residual sum of squares. Validation error, cross-validation, , AIC, BIC, or adjusted compare models that have different numbers of coefficients. For a least-squares fit with predictors, one estimate of test mean squared error is . The penalty term is what can make a larger subset look worse.[1]
Subset selection and shrinkage are the two standard organisations of this idea in linear regression. Dimensionality reduction is the third organisation in the same chapter, and it is not feature selection: every original predictor can still appear inside a principal component. The component may be a useful summary, but it does not drop a named variable from the equation.[1]
A smaller training residual sum of squares does not mean a better selected model. On the three cases, and both have training residual sum of squares . The second model is not more accurate on new cases merely because it contains an extra predictor. Training error is why the size of the subset is chosen by a validation score or by a penalty such as , not by residual sum of squares itself.[1]
Forward stepwise is not best subset selection on a budget that happens to reach the same answer. It is a nested search. The three-case example happens to agree at size . The search disagrees as soon as the best pair does not contain the best single predictor.[1] [2]
Ridge regression is not a feature-selection method. Shrinking a coefficient is not the same as removing the predictor. The square penalty leaves every coefficient nonzero for any finite penalty. The lasso is the penalty that removes predictors.[1] [2]
The comparisons above use squared error, an intercept, and predictors that enter as they are. A monotone transformation of , or a penalty on coefficients that have not been put on a common scale, changes which variable looks useful. Best subset and stepwise selection, followed by ordinary least squares on the chosen subset, treat the selected variables as if they had been named in advance. The selection search is part of the fitting, and a later standard error that ignores the search is too small.[1] [2]
A large search overfits. With enough candidate predictors, some subset will look good on the training set and fail on new cases. That is why is already described as a statistical problem for best subset selection, not only a computational one. Forward stepwise reduces the number of subsets, and it can still overfit the order in which variables were added.[1] [2]
Quadratic regularisation does not become feature selection by discarding small weights after the fit and refitting. That backward trick has been tried on a support-vector classifier with thousands of genes and a few hundred samples, and the accuracy fell as genes were removed. An penalty builds the zeros into the fit instead.[2]
Worked example
Take the three cases , , .
The sample mean of is . The intercept-only residual sum of squares is
The least-squares line in is . Its fitted values are , and , and the residual sum of squares is
The line fits all three points, so its residual sum of squares is .
Best subset selection of size therefore returns . Forward stepwise starts from the intercept, compares the drop from to against the drop from to , and adds . The two-predictor fit also has residual sum of squares , because it can set the coefficient of to zero and keep . Training residual sum of squares does not prefer the one-predictor model.
For a separate count, predictors give best-subset models and forward-stepwise models.
Your turn. On these three cases, what is the training residual sum of squares of the intercept-only model, and of the least-squares model that uses only ?
The intercept-only residual sum of squares is . The model that uses only has residual sum of squares .
Connections
Subset selection and shrinkage are the paired tools. The lasso and the logistic lasso are the shrinkage versions that set coefficients to zero. Ridge regression shrinks without selection. Dimensionality reduction replaces predictors by a few combinations rather than by a subset. Cross-validation is the usual way to choose how many variables, or how large a penalty, to keep. Overfitting is what a selection rule is trying not to do when it refuses the subset with the smallest training error.[1] [2]
Check yourself
Try these questions before opening an answer.
Intercept-only residual sum of squares
For the cases (x, z, y) = (0, 0, 1), (1, 0, 1) and (2, 1, 3), what is the residual sum of squares of the intercept-only fit?
The residual sum of squares is 8/3.
Predictor x alone
On the same three cases, what is the residual sum of squares of the least-squares line that uses only x and an intercept?
The residual sum of squares is 2/3.
How many best-subset models
Best-subset selection with 20 predictors fits how many models, and forward stepwise fits how many?
Best subset fits 1048576 models. Forward stepwise fits 211.
History
Subset search is the older organisation: all subsets of each size when is moderate, and a forward or backward path when it is not. The leaps-and-bounds algorithm made an exhaustive subset search practical for a few dozen predictors. Forward stepwise, a greedy nested path, and backward deletion of the weakest coefficient were the practical substitutes, with the warning that the path need not contain the best subset of each size.[2] [1]
The lasso made selection a property of one convex penalty rather than of a search over subsets. In high-dimensional classification the distinction became sharp: square penalties on discriminant analysis, logistic regression, and support-vector machines keep every feature, while an absolute penalty sets some coefficients to zero and so selects.[1] [2]
See also
Line chart · Apriori algorithm · Asymptotic analysis · Average treatment effect · Base rate · Bayesian inference · Bayesian model · Bayesian probability
References
- ^ a b c d e f g h i j k l m n o p q r s t a. (Ch. 6, pp. 225–226) b. (Ch. 6, pp. 227–228) c. (Ch. 6, pp. 225–226) d. (Ch. 6, pp. 226–231, 241–242) e. (Ch. 6, p. 228) f. (Ch. 6, pp. 225–226) g. (Ch. 6, pp. 227–228) h. (Ch. 6, pp. 228–231) i. (Ch. 6, pp. 241–242) j. (Ch. 6, pp. 228–231) k. (Ch. 6, pp. 227–228, 233, (6.2)) l. (Ch. 6, p. 226) m. (Ch. 6, pp. 227–228) n. (Ch. 6, pp. 230–231) o. (Ch. 6, pp. 241–242) p. (Ch. 6, pp. 229–231) q. (Ch. 6, p. 229) r. (Ch. 6, pp. 226–228, 241–242) s. (Ch. 6, pp. 227–231) t. (Ch. 6, pp. 241–242) James, G., Witten, D., Hastie, T. & Tibshirani, R. (2021). An Introduction to Statistical Learning: with Applications in R (2nd ed.). Springer, New York. https://doi.org/10.1007/978-1-0716-1418-1
- ^ a b c d e f g h i j k l m n o p q a. (p. 57, §3.3) b. (p. 57, §3.3) c. (pp. 57–59, §3.3; p. 661, §18.4) d. (p. 658, §18.3.4; p. 661, §18.4) e. (p. 57, §3.3) f. (p. 57, §3.3.1) g. (pp. 58–59, §3.3.2) h. (p. 661, §18.4, (18.18)) i. (pp. 57–59, §3.3) j. (pp. 58–59) k. (pp. 658, 661) l. (pp. 58–59) m. (pp. 58–59) n. (p. 658, §18.3.4; p. 661, §18.4) o. (pp. 57–59, 658, 661) p. (pp. 57–59, §3.3) q. (p. 658, §18.3.4; p. 661, §18.4) Hastie, T., Tibshirani, R. & Friedman, J. (2009). The Elements of Statistical Learning. Springer. https://doi.org/10.1007/978-0-387-84858-7
Cite this page
StatWiki (2026). "Feature selection." StatWiki. Last updated 2 December 2026. https://www.statwiki.io/articles/feature-selection.html
@misc{statwiki_feature_selection,
author = {{StatWiki}},
title = {{Feature selection}},
year = {2026},
url = {https://www.statwiki.io/articles/feature-selection.html},
urldate = {2026-12-02},
note = {StatWiki, last updated 2 December 2026}
}