Effective Complexity & Degrees of Freedom
Measuring model complexity: covariance penalties, SURE and the lasso.
How complex is a model? Counting parameters fails in both directions: a single parameter can fit arbitrarily many labelings, and a ridge fit with a thousand coefficients can behave like one with ten. This lesson measures complexity by what a fit does, how strongly each fitted value follows its own label, and derives the tools built on that idea: Mallows' , AIC, Stein's unbiased risk estimate, and the surprising degrees of freedom of the lasso.
What you’ll learn
- Prove the optimism identity , define degrees of freedom, and compute it for linear smoothers, ridge and -NN.
- Prove Stein's lemma and SURE, and use SURE to show that the James–Stein estimator beats the sample mean for every mean vector in dimension 3 or more.
- Compute the degrees of freedom of soft and hard thresholding, state the lasso results, and explain the hidden cost of searching over subsets.
- Explain what , AIC and cross-validation each estimate, and how they relate.
Parameter counts mislead
Four examples show why the number of parameters is a poor measure of complexity:
- One parameter, unlimited capacity. The classifiers have one parameter, yet for every some points can be labeled in all ways (VC dimension ; shown in Learning Theory: How Many Examples Are Enough?).
- Many parameters, little capacity. Ridge regression with a large penalty keeps all coefficients but lets them move very little.
- No parameters at all. -nearest neighbors fits nothing, yet with it reproduces every training label.
- Search costs complexity. Choosing the best 3 of 100 candidate predictors, then fitting 3 coefficients, adapts to the data far more than a model whose 3 predictors were fixed in advance.
A useful definition must look at how the fit responds to the data.
Optimism and covariance penalties
Work with a fixed design: inputs are held fixed and with and . A fitting rule produces . The training error is , and the in-sample error uses fresh labels , an independent copy of at the same inputs.
The fresh label is independent of , so only the noise variance and the estimation error remain:
For the training label, the noise and the fit are correlated, and :
Subtract and average over . Nothing about the fitting rule was used: it may be nonlinear, adaptive, or chosen by search.
For a linear smoother , with depending on the inputs but not on , , so :
- least squares with linearly independent columns: ;
- ridge: in terms of the singular values of , falling continuously from to (Ridge Regression in Depth);
- -NN regression, where each training point counts itself among its neighbors (no ties): , so ;
- fitting a constant: and .
Plugging df into the optimism gives Mallows' (1973), , an unbiased estimate of when df is known exactly and is unbiased. AIC (Akaike, 1974), for a model with parameters, is an asymptotically unbiased estimate of the expected out-of-sample deviance for correctly specified regular models; for Gaussian regression with known it is up to scaling and constants. Its small-sample correction AICc (Hurvich & Tsai, 1989) adds .
A -nearest-neighbor regression with is fitted to points (each point counts itself as a neighbor, no ties). How many degrees of freedom does it use?
Show the answer
20
Each fitted value gives weight to its own label, so and : as many as a least-squares fit with 20 coefficients, from a method with no fitted parameters at all. With , and the training error is zero.
Stein's lemma and SURE
In one dimension, for the density . Integrate by parts (the boundary terms vanish under the integrability condition):
Apply this to coordinate , conditioning on the others (independent under isotropic noise), to get . Then expand the risk around :
The middle term is , and the last is :
Shrink toward zero by a data-dependent factor: . Since ,
Substitute into SURE. The risk of the unbiased estimator is for every ; James–Stein is strictly better for every , since is finite and positive when :
Take and true mean . Then , and . What is the James–Stein risk as a percentage of the sample mean's risk ?
Show the answer
20 %
, so the risk is , whatever is: of the sample mean's risk. Far from the gain shrinks toward zero, but it never turns into a loss.
Thresholding, the lasso and the cost of search
With an orthonormal design the lasso reduces to soft thresholding of each coordinate, , and best-subset selection to hard thresholding, . Both keep the coordinates with ; they differ in what they do to the survivors.
Soft thresholding is continuous and piecewise linear, with derivative almost everywhere. Stein's lemma applies, and : the expected number of nonzero coefficients. Its SURE, , is what Donoho & Johnstone (1995) minimized to choose (SureShrink).
This is remarkable: the lasso picks its active set from the data, yet pays only for the size of the set. Shrinking the survivors toward zero exactly offsets the optimism of selecting them. Hard thresholding has no such discount. It jumps at , so Stein's lemma fails, and a direct computation for one coordinate with , gives
Think first At (with , ), the expected number of nonzeros is . Estimate the degrees of freedom of hard thresholding before revealing.
The search term is , so : about 5.7 times the expected number of nonzeros. A coordinate survives only when its noise happens to be large, and then it is kept at full size, so the fit follows its noise strongly. Ye (1998) introduced generalized degrees of freedom to measure this effect in adaptive procedures such as variable selection and regression trees, and Janson, Fithian & Hastie (2015) showed that for nonconvex procedures df can be non-monotone in the size constraint, can exceed the dimension of the space, and for nonconvex projection methods can be unbounded.
| Procedure | Degrees of freedom | Why |
|---|---|---|
| least squares, fixed predictors | ||
| ridge | shrinkage reduces sensitivity | |
| -NN (point counts itself) | each fit weighs its own label by | |
| lasso | (full-rank ), in general | selection and shrinkage cancel |
| best subset of size | typically more than | selection without shrinkage |
What the criteria estimate
, AIC and SURE estimate in-sample error: new labels at the same inputs. Cross-validation estimates out-of-sample error at new inputs, for a model trained on slightly fewer points. For large the two often agree: Stone (1977) proved that choosing a model by leave-one-out cross-validation and by AIC are asymptotically equivalent under regularity conditions. With few points per parameter, or high-leverage inputs, they can differ, because extrapolating to new inputs costs more than refitting at old ones.
Efron (2004) related the two families through a Rao–Blackwell-type argument, in which cross-validation acts like a randomized version of a covariance penalty, and concluded that model-based penalties are more accurate when the model is believable, while cross-validation needs fewer assumptions. For procedures without a formula for df, such as trees or boosting, the covariance can be estimated by a parametric bootstrap: perturb , refit, and regress the fitted values on the perturbations.
Key takeaways
- Training error is optimistic by exactly ; degrees of freedom measure complexity by sensitivity to the labels, not by counting parameters.
- Linear smoothers have : for least squares, for ridge, for -NN. and AIC add to the training error.
- Stein's lemma turns the covariance into an expected divergence, giving SURE, an unbiased risk estimate for Gaussian noise; applied to James–Stein it proves that shrinkage beats the sample mean for every mean in dimension .
- The lasso's df equal its expected number of nonzeros ( in general): shrinkage pays for selection. Hard thresholding and best subset pay an extra search cost, and for nonconvex methods df can exceed the dimension.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
A fitting rule sets for every (it interpolates its labels). What are its degrees of freedom?
- It depends on
Show the answer
C.
for every , so ; equivalently and . The training error is zero and the optimism is : the fit copies every bit of the noise.
Which assumptions does Stein's unbiased risk estimate need?
- A linear estimator and any noise distribution
- Gaussian noise with known variance and a weakly differentiable estimator
- A correctly specified model and a large sample
- An estimator with a closed-form formula for its bias
Show the answer
B. Gaussian noise with known variance and a weakly differentiable estimator
Stein's lemma is an integration by parts against the Gaussian density, so the noise must be Gaussian (with known to evaluate SURE), and must be weakly differentiable. The estimator can be nonlinear and the model wrong: SURE is unbiased for the risk regardless.
With an orthonormal design, the lasso and best-subset selection keep the same coordinates at matching thresholds. How do their degrees of freedom compare?
- Equal, because they select the same variables
- The lasso's equal its expected number of nonzeros; best subset's exceed it, because it keeps the selected coefficients at full size
- The lasso's are larger, because it uses an penalty
- Neither has well-defined degrees of freedom
Show the answer
B. The lasso's equal its expected number of nonzeros; best subset's exceed it, because it keeps the selected coefficients at full size
Soft thresholding is continuous, and Stein's lemma gives . Hard thresholding jumps at the threshold and adds a search cost per null coordinate (with ), so at its degrees of freedom are about 5.7 times its expected number of nonzeros.
Mallows' is an unbiased estimate of which quantity?
- The error on new labels at the same inputs (in-sample error)
- The error at new inputs drawn from the population
- The training error
- The Bayes error
Show the answer
A. The error on new labels at the same inputs (in-sample error)
The optimism identity compares training error with fresh labels at the same , so targets . Error at new inputs adds the cost of extrapolation, which cross-validation captures and does not.
Further reading
- B. Efron, "The estimation of prediction error: covariance penalties and cross-validation," Journal of the American Statistical Association 99(467), 619–632 (2004).
- C. M. Stein, "Estimation of the mean of a multivariate normal distribution," Annals of Statistics 9(6), 1135–1151 (1981).
- H. Zou, T. Hastie & R. Tibshirani, "On the 'degrees of freedom' of the lasso," Annals of Statistics 35(5), 2173–2192 (2007).
- R. J. Tibshirani & J. Taylor, "Degrees of freedom in lasso problems," Annals of Statistics 40(2), 1198–1232 (2012).
- L. Janson, W. Fithian & T. J. Hastie, "Effective degrees of freedom: a flawed metaphor," Biometrika 102(2), 479–485 (2015).