Tutorials › Exam SRM - Statistics for Risk Modeling › Polynomial Degree as a Bias-Variance Case Study

Exam SRM · Bias, Variance, and Overfitting · Tutorial 769 of 926

Polynomial Degree as a Bias-Variance Case Study

Learn how polynomial degree changes fit flexibility, training error, validation performance, and sensitivity to the training sample.

Intermediate 10 min read

What You'll Learn

  • Define nested polynomial regression models and compare their degrees of flexibility
  • Calculate and interpret training and validation mean squared errors
  • Explain why training error cannot increase as polynomial degree increases
  • Connect polynomial flexibility with approximation bias and sample sensitivity
  • Recognize when a very low or high degree is a warning sign
  • Avoid choosing a degree solely because it has the smallest training error

Why Polynomial Degree Is a Useful Case Study

A polynomial regression model can represent a straight-line trend, a curved trend, or a more intricate pattern by changing only its degree. That makes polynomial degree a direct way to study model flexibility. A degree that is too low may miss systematic curvature; a degree that is very high may adapt closely to the particular training observations without predicting new observations as well.

The comparison is not “simple is always better” or “more flexible is always better.” The practical question is whether added flexibility improves prediction beyond the data used to fit the model. Training error describes fit to the observations used for estimation. Validation error measures prediction error on a separate set of observations not used to fit the coefficients. Both are needed to see the characteristic pattern: training error tends to fall with degree, while validation error may fall and then rise.

Definition: For a predictor \(x\), a polynomial regression model of degree \(d\) has fitted function \(\widehat f_d(x)=\widehat\beta_0+\widehat\beta_1x+\cdots+\widehat\beta_dx^d\). Its degree is the largest power included. Degree 1 is a straight line; degree 2 allows curvature; higher degrees allow more changes in shape. The degree-\(d\) model class contains every lower-degree polynomial model, by setting the coefficients of the added powers to zero.

For a set of \(n\) observations with responses \(y_i\) and fitted predictions \(\widehat f_d(x_i)\), the mean squared error (MSE) is the average squared prediction error. Training MSE uses the observations that determined the fitted coefficients. Validation MSE uses observations held out from that fitting calculation. In a fair comparison, the degrees are assessed on the same training observations and the same validation observations, using the same response scale and loss.

$$ \operatorname{MSE}_{\mathrm{train}}(d) =\frac{1}{n}\sum_{i=1}^{n}\left(y_i-\widehat f_d(x_i)\right)^2, \qquad \operatorname{MSE}_{\mathrm{validation}}(d) =\frac{1}{m}\sum_{j=1}^{m}\left(y_j^{\mathrm{val}}-\widehat f_d(x_j^{\mathrm{val}})\right)^2. $$

Here \(m\) is the number of validation observations. Validation responses are used to score predictions, not to estimate the coefficients in \(\widehat f_d\). A small validation set can produce a noisy comparison, so an observed minimum is evidence for a useful degree, not proof that the degree is universally best.

How Degree Relates to Bias and Variance

Suppose the response at a fixed predictor value \(x_0\) follows \(Y_0=f(x_0)+\varepsilon_0\), where \(f(x_0)\) is the true mean response, and \(\varepsilon_0\) has mean zero and variance \(\sigma^2\). Assume the new error is independent of the training sample used to obtain \(\widehat f_d\). Averaging prediction error over possible training samples and new responses gives:

$$ E\!\left[(Y_0-\widehat f_d(x_0))^2\right] = \sigma^2+ \left(E[\widehat f_d(x_0)]-f(x_0)\right)^2 +\operatorname{Var}(\widehat f_d(x_0)). $$

The squared difference between the average fitted prediction and the true mean is squared bias; the variance term measures how much that fitted prediction changes across training samples. The noise term cannot be removed by choosing a different polynomial degree. A low-degree polynomial can have substantial bias if the underlying mean curve bends in a way the model cannot represent. Increasing degree can reduce that approximation bias, but may make fitted predictions more sensitive to which observations happened to be in the training sample.

The decomposition follows by adding and subtracting \(E[\widehat f_d(x_0)]\) inside the squared error. Write \(a=E[\widehat f_d(x_0)]\). Then \(Y_0-\widehat f_d=(Y_0-f)+(f-a)+(a-\widehat f_d)\). On squaring and taking expectations, the cross-products vanish: the new noise has mean zero and is independent of the fitted prediction, while \(E[a-\widehat f_d]=0\). The remaining terms are \(E[(Y_0-f)^2]=\sigma^2\), \((f-a)^2\), and \(E[(a-\widehat f_d)^2]=\operatorname{Var}(\widehat f_d)\), which gives the formula.

This explains the bias-variance interpretation without claiming that degree alone determines either quantity in every problem. The shape of the true relationship, the spread and locations of observed \(x\)-values, sample size, and noise all matter. A degree that works well for one range of predictors or sample size may not work equally well in another setting.

Worked Example: Finding the Useful Degree From Error Scores

In a hypothetical study of claim-processing time, the response is measured in hours. Four polynomial models are fitted to the same training sample and scored on the same validation sample. Their MSEs, in squared hours, are shown below. Which degree has the smallest validation error, and what pattern do the results suggest?

DegreeTraining MSEValidation MSE
10.640.72
20.390.43
50.160.31
80.050.58

Step 1: Compare validation errors. The values are 0.72, 0.43, 0.31, and 0.58. Their minimum is 0.31, so degree 5 has the lowest observed validation MSE.

Step 2: Compare the added flexibility. Moving from degree 1 to degree 2 reduces validation MSE by \(0.72-0.43=0.29\). Moving from degree 2 to degree 5 reduces it by a further \(0.43-0.31=0.12\). Moving from degree 5 to degree 8 increases it by \(0.58-0.31=0.27\), even though training MSE falls from 0.16 to 0.05.

Step 3: Interpret the pattern. The degree-1 model may be too rigid for the relationship, while degree 8 fits its training observations much more closely without a corresponding validation improvement. Among these candidates, degree 5 is the best choice by validation MSE. This is a comparison of the available candidates, not a guarantee about all possible degrees or future data.

Method and trap avoided. The method is to select by the stated validation loss and then interpret the train-validation pattern. Choosing degree 8 because it has the smallest training MSE would confuse fit to training data with prediction performance.

Training Error Falls; Validation Error Need Not

When polynomial models are fitted by minimizing squared error on the same training observations, the training errors cannot increase as degree increases, provided each larger model is an unconstrained extension of the smaller model. The degree-\((d+1)\) model can reproduce the degree-\(d\) fit by choosing \(\widehat\beta_{d+1}=0\). Since the larger class includes that fit, its minimum training sum of squared errors is no greater. Dividing by the unchanged \(n\) preserves the inequality for training MSE.

This result concerns the optimized training loss, not validation error. Validation observations were not used to minimize the fitting criterion, so a more flexible polynomial has no mathematical obligation to predict them better. High-degree polynomials can bend sharply between or beyond observed predictor values. Small changes in the training observations can also alter those bends, a sign of increased sample sensitivity.

The argument assumes the same rows, response, loss, and fitting objective at each degree, with the lower-degree model available inside the larger model. It may not describe a comparison where the sample changes, coefficient constraints change, or a penalty is added. Polynomial fitting can also be numerically unstable at high degrees, particularly when powers of \(x\) have very different scales. Scaling \(x\) can help numerical computation, but it does not turn training error into a reliable measure of generalization.

Worked Example: Repeated Samples Reveal Sensitivity

A hypothetical analyst compares degree 2 and degree 7 polynomials across four repeated training samples of the same size. Each model is scored on a validation sample for its corresponding repetition. The MSEs are:

RepetitionDegree 2 trainingDegree 2 validationDegree 7 trainingDegree 7 validation
10.380.420.080.20
20.390.440.120.72
30.370.400.070.31
40.380.430.110.89

Step 1: Average training MSE. For degree 2, the total is \(0.38+0.39+0.37+0.38=1.52\), so the mean is \(1.52/4=0.38\). For degree 7, the total is \(0.08+0.12+0.07+0.11=0.38\), so the mean is \(0.38/4=0.095\).

Step 2: Average validation MSE. For degree 2, the total is \(0.42+0.44+0.40+0.43=1.69\), giving \(1.69/4=0.4225\). For degree 7, the total is \(0.20+0.72+0.31+0.89=2.12\), giving \(2.12/4=0.53\).

Step 3: Compare variation across repetitions. Degree 2's validation errors range from 0.40 to 0.44, a range of \(0.44-0.40=0.04\). Degree 7's range from 0.20 to 0.89, a range of \(0.89-0.20=0.69\). Thus degree 7 has much lower average training MSE, but higher average validation MSE and a much wider spread of validation scores.

Conclusion. These results are consistent with the degree-7 fit being more sensitive to the particular training sample. The repeated-score range is a descriptive indication of instability, not a formal estimate of prediction variance. The method avoids relying on a single unusually good validation result.

A Small Polynomial Fit Worked Directly

A table of scores is often enough to diagnose a degree comparison, but understanding the fitted polynomials clarifies what the scores represent. The next example computes the coefficients and errors directly. It uses a deliberately small data set so every least-squares calculation can be checked.

Worked Example: A Linear Fit Misses a Curved Pattern

A hypothetical sensor records response \(y\) at predictor values \(x=-1,0,1\), giving responses \(2,1,2\), respectively. Fit degree 1 and degree 2 by least squares. Then score them at validation points \(x=-0.5\) and \(x=0.5\), where the observed responses are both 1.25. Use MSE with the number of observations as the denominator.

Step 1: Fit the degree-1 model. Its intercept is the mean response, \(\widehat\beta_0=(2+1+2)/3=5/3\). The predictor mean is \((-1+0+1)/3=0\). The slope numerator is \((-1)(2-5/3)+0(1-5/3)+1(2-5/3)=-1/3+0+1/3=0\); the denominator is \((-1)^2+0^2+1^2=2\). Hence \(\widehat\beta_1=0/2=0\), and every fitted value is \(5/3\).

Step 2: Calculate degree-1 training MSE. The residuals are \(2-5/3=1/3\), \(1-5/3=-2/3\), and \(2-5/3=1/3\). Thus the sum of squared errors is \((1/3)^2+(-2/3)^2+(1/3)^2=1/9+4/9+1/9=6/9=2/3\). The training MSE is \((2/3)/3=2/9\).

Step 3: Fit the degree-2 model. The polynomial \(1+x^2\) gives fitted values \(2,1,2\) at \(x=-1,0,1\), exactly matching the data. Therefore its coefficients are \(\widehat\beta_0=1\), \(\widehat\beta_1=0\), and \(\widehat\beta_2=1\), and its training MSE is 0.

Step 4: Calculate validation MSEs. At either validation point, the linear fit predicts \(5/3\). Its error is \(5/3-1.25=5/3-5/4=5/12\), so each squared error is \(25/144\). The degree-1 validation MSE is \((25/144+25/144)/2=25/144\). The quadratic predicts \(1+(-0.5)^2=1.25\) and \(1+(0.5)^2=1.25\), so its validation MSE is 0.

Check and interpretation. The degree-2 training and validation errors are both zero because these observations lie exactly on the stated quadratic curve. The linear model has positive errors on both sets. Here the additional flexibility captures real curvature. The example avoids the trap of assuming that every increase in degree is overfitting; the validation result determines whether the added flexibility helped in this case.

Common Mistakes and Practical Interpretation

  • Selecting the smallest training MSE. Nested polynomial classes make this score fall or remain unchanged as degree increases. It does not by itself identify the degree that predicts new observations best.
  • Calling every high-degree model overfit. A higher degree can improve validation performance when the lower-degree model misses important curvature. Overfitting is a concern when the training fit improves while validation performance worsens, not merely when the degree is large.
  • Comparing scores from different setups. MSEs are not directly comparable if one degree uses different rows, a different response scale, or a different validation set. Check that the comparison is like-for-like.
  • Ignoring variability in the comparison. A modest validation advantage on one small sample may not persist across new training samples. Repeated comparisons can reveal whether one degree's apparent performance is unusually unstable.
  • Extrapolating from the observed predictor range. A polynomial that fits well within the data range can behave erratically beyond it. Validation points far outside the training range test extrapolation as well as degree; interpret such scores in that context.
Key takeaway: Polynomial degree controls flexibility, not predictive quality by itself. Compare degrees using training and validation errors computed consistently. A low degree may underfit; a high degree may be sample-sensitive; and the useful choice is the one that balances these effects on data not used to fit its coefficients.

Check Your Understanding

For each problem, use the stated loss and data comparison; answers are included for checking.

  1. A hypothetical model comparison reports validation MSEs of 0.57, 0.39, and 0.46 for degrees 1, 2, and 4. Training MSEs are 0.50, 0.32, and 0.20. Which candidate has the smallest validation error, and by how much does its validation MSE beat degree 4? (Answer: Degree 2; \(0.46-0.39=0.07\).)
  2. Across three repeated fits of degree 6, validation MSEs are 0.24, 0.66, and 0.30. Compute their mean and range. (Answer: Mean \(=(0.24+0.66+0.30)/3=0.40\); range \(=0.66-0.24=0.42\).)
  3. For training data \((-1,0),(0,2),(1,0)\), find the degree-1 fitted intercept and slope, then its training MSE. (Answer: Intercept \(2/3\), slope \(0\); MSE \(8/9\).)
  4. For the data in question 3, a degree-2 model predicts each training response exactly. At validation point \(x=0.5\), the observed response is 1.5 and the fitted quadratic prediction is 1.5. What is its validation squared error at this point, and what limitation should be remembered if only this one validation point is used? (Answer: Squared error \(0\); one point provides a limited and potentially unstable assessment of prediction performance.)
  5. At one fixed \(x_0\), a model has squared bias 0.09, prediction variance 0.16 across training samples, and independent response noise variance 0.25. Under the squared-error decomposition, what is the expected prediction error? (Answer: \(0.09+0.16+0.25=0.50\).)
Clinical Biostats