Subset Selection

Today

  • Used car prices
  • Best subset selection
    • Algorithm
    • Fitting
    • Training RSS
    • Computational cost
  • Stepwise selection
    • Forward stepwise
    • Backward stepwise
    • Path comparison
  • Model size
    • Penalized criteria
    • Likelihood criteria
    • Within-fold cross-validation
    • Chosen sizes
  • Selected model
    • Coefficients
    • Optimistic inference

Used car prices

Price scale

Candidate features

  • Response variable: \(\log(\texttt{Price})\)
  • Explanatory variables: Mileage, Cylinder, Doors, Cruise, Sound, Leather, make, body style
  • Features, \(p = 14\): Mileage, Cylinder, Cruise, Sound, Leather, Buick, Cadillac, Chevy, Pontiac, Saab, convertible, coupe, hatchback, sedan
  • Reference levels: Saturn, wagon

Selection motives

  • Interpretability
  • Variance
  • Search: \(2^p\) candidate models

Best subset selection

Algorithm

  1. \(\mathcal{M}_0\): the null model, no features
  2. For \(d = 1, \ldots, p\): fit all \(\binom{p}{d}\) models with \(d\) features; \(\mathcal{M}_d\) is the one with the smallest RSS
  3. Choose among \(\mathcal{M}_0, \ldots, \mathcal{M}_p\) by \(C_p\), BIC, adjusted \(R^2\), or cross-validation

Fitting

Training RSS

Computational cost

  • \(2^p\) least squares fits
  • \(2^{14} = 16{,}384\) for these cars
  • \(2^{20}\) is about a million
  • \(2^{30}\) about a billion
  • \(2^{40}\) about a trillion

Stepwise selection

Forward stepwise

  1. \(\mathcal{M}_0\): the null model
  2. For \(d = 0, \ldots, p - 1\): add the one feature to \(\mathcal{M}_d\) with the smallest RSS to get \(\mathcal{M}_{d+1}\)
  3. Choose among \(\mathcal{M}_0, \ldots, \mathcal{M}_p\) as in best subset selection

\[1 + \sum_{d=0}^{p-1}(p - d) = 1 + \frac{p(p+1)}{2}\]

106 models for \(p = 14\), against 16,384 for best subset selection

Backward stepwise

  1. \(\mathcal{M}_p\): the model with all \(p\) features
  2. For \(d = p, \ldots, 1\): remove the one feature from \(\mathcal{M}_d\) that leaves the smallest RSS to get \(\mathcal{M}_{d-1}\)
  3. Choose among \(\mathcal{M}_0, \ldots, \mathcal{M}_p\) as before

Greedy: forward never removes a feature it has added, backward never restores one it has removed

Path comparison

Method Size 1 (RSS) Size 2 (RSS) Size 3 (RSS)
Best subset Cadillac (44.51) Cylinder + Saab (14.51) Cylinder + Cadillac + Saab (9.56)
Forward Cadillac (44.51) Cadillac + Saab (27.51) Cylinder + Cadillac + Saab (9.56)
Backward Cylinder (45.52) Cylinder + Saab (14.51) Cylinder + Cadillac + Saab (9.56)

Model size

Training MSE

Training error optimism

\[E\left[\sum_{i=1}^n\left(y_i^0 - \widehat y_i\right)^2\right] = E\left[RSS\right] + 2\sigma^2\,\text{tr}(\mathbf{H}) = E\left[RSS\right] + 2(d+1)\sigma^2\]

  • \(y_i^0\) — new response at \(x_i\)
  • \(\mathbf{H}\) — hat matrix
  • \(d\) — number of features

Penalized criteria

\[C_p = \frac{1}{n}\left(RSS + 2d\widehat\sigma^2\right)\]

\[\text{BIC} = \frac{1}{n}\left[RSS + \log(n)\,d\widehat\sigma^2\right]\]

\[\text{Adjusted } R^2 = 1 - \frac{RSS/(n - d - 1)}{TSS/(n - 1)}\]

  • \(RSS\) — training residual sum of squares
  • \(d\) — number of features
  • \(\widehat\sigma^2\) — error variance estimate from the model with all \(p\) features
  • \(TSS\) — total sum of squares

Choose the smallest \(C_p\) or BIC, the largest adjusted \(R^2\)

Likelihood criteria

\[\log L = -\frac{n}{2}\log\left(2\pi\widehat\sigma^2\right) - \frac{RSS}{2\widehat\sigma^2}\]

\[\text{AIC} = -2\log L + 2(d + 1), \qquad \text{BIC} = -2\log L + \log(n)(d + 1)\]

  • \(L\) — maximized likelihood under \(\epsilon_i \stackrel{ind}{\sim} N\left(0, \sigma^2\right)\) with \(\sigma^2\) fixed at \(\widehat\sigma^2\)
  • \(d + 1\) — coefficients, including the intercept

Within-fold cross-validation

  • Best subset search inside each fold, from the training folds only
  • Predict the held-out fold with the best model of each size
  • \(\text{CV}_{(k)}(d)\) estimates the test MSE of the procedure “fit the best model of size \(d\)”

Chosen sizes

Selected model

Coefficients

Change in median price per 10,000 miles for Mileage, per cylinder for Cylinder, and from 0 to 1 for each indicator.
Feature \(\widehat\beta_j\) Change in median price
(Intercept) 9.015
Mileage -8.199e-06 -7.9%
Cylinder 0.1865 20.5%
Leather 0.03446 3.5%
Buick 0.1204 12.8%
Cadillac 0.4288 53.5%
Saab 0.7032 102.0%
convertible 0.1572 17.0%
coupe -0.1178 -11.1%
hatchback -0.2924 -25.4%
sedan -0.1681 -15.5%

Reference make

  • Dropped: Cruise, Sound, Chevy, Pontiac
  • Reference make: Chevy, Pontiac and Saturn together
  • Dropping a dummy variable merges its level into the reference

Optimistic inference

Conclusion

  • Training error always falls as features are added, so it cannot choose model size
  • Best subset selection searches every model; stepwise selection is cheaper but greedy
  • \(C_p\), AIC, BIC and adjusted \(R^2\) penalize model size
  • Cross-validation chooses model size too, with the search repeated inside every fold
  • Selection makes standard errors and \(p\)-values optimistic