03:00

Assessing Accuracy
Grayson White
Stat 243
Week 2 | Fall 2026
Today:
Friday (NOT lab):
For each of the following scenarios, identify if it is primarily a…
Prediction or Inference task
Parametric or Non-Parametric method
Supervised or Unsupervised problem
Regression or Classification problem
03:00
Insomnia Cookies wants to better understand their customers, so they conduct a small survey and ask customers their age (\(X_1\)) and hours worked per week (\(X_2\)).
What can Insomnia Cookies infer about their customers?
Label each “cluster”.
Determine whether this is supervised or unsupervised learning, and explain why.

02:00
The function \(f\) is called the model or regression function and the random variable \(\epsilon\) is the error term
The function \(f\) represents our best estimate of the value of \(Y\) given \(X\), or the expected value of \(Y\) given \(X\) (sometimes written: \(E[Y \vert X]\))
Consider two quantitative variables \(X\) and \(Y\)

Consider two quantitative variables \(X\) and \(Y\)
Suppose, in truth, \(Y = 1 + 2X + \epsilon\), where \(\epsilon \sim N(\mu = 0, \sigma = 0.25)\).
But data \(Y\) will not always lie on this line:

Consider two quantitative variables \(X\) and \(Y\)
In reality, we won’t know the true model.
We only have the observed data

Consider two quantitative variables \(X\) and \(Y\)
Instead, we create an estimate \(\hat f\) based on data
Here, we use least squares regression (minimizing MSE) to estimate \(f\)

Consider two quantitative variables \(X\) and \(Y\)
Our estimated model is \(\hat f(x) = 1.14 + 1.77x\)
Which is close to the true model of \(f(x) = 1 + 2x\)

There are two sources of error in a model, \[ \hat{Y} = \hat{f}(X) \] for the true relationship, \[ Y = f(X)+\epsilon \]
\[ \text{Error} = Y - \hat{Y} = \underbrace{(f - \hat{f})}_{\text{Reducible}} + \underbrace{\epsilon}_{\text{irreducible}} \]
Reducible error: in the form of our estimate \(\hat{f}\) for \(f\).
Irreducible error: in the form of \(\epsilon\).
When given a modeling question, we can conceive of many possible models.
How should we measure quality of a model?
Devise a quantitative measurement of model error.
Select the model that minimizes this measure of error.
For regression, the most common measure of error is the Mean Squared Error (MSE): \[ \mathrm{MSE}(\hat{f}) = \frac{1}{n}\sum_{i=1}^n \Big(y_i - \hat{f}(x_i) \Big)^2, \] where \(\hat{f}\) is the model, \(x_i\) are the observed predictor values, and \(y_i\) are the corresponding observed response values.
Recall: other options like MAE and MZOL are popular for particular applications or regression and classification.
\[ \mathrm{MSE}(\hat{f}) = \frac{1}{n}\sum_{i=1}^n \Big(y_i - \hat{f}(x_i) \Big)^2 \]
Q: Under what circumstances is MSE small?
Q: What could go wrong if we try to minimize \(\mathrm{MSE}\) on observed data?
We can solve this problem by dividing our data into training and test sets.
Training Data: Subset used for building a model
Test Data: Rest of data used for assessing model accuracy
If we have training and test data, we can:
Build many models on the training data
Compare their performance on the test data (e.g., compare MSE)
Select the model that did the best on the test data
Suppose we have 50 observations on a quantitative response \(Y\) and quantitative predictor \(X\)
We plan to use 70% of our data (35 observations) as a training set and the remaining 30% of the data (15 observations) as a test set.
We will fit three models:
A linear model; low flexibility
A quintic model; medium flexibility
A degree 15 model; high flexibility


Now, we can compute the training MSE for these models:
lin_mod <- lm(Y ~ X, data = my_df)
lin_pred_train <- predict(lin_mod, my_df)
quintic_mod <- lm(Y ~ poly(X, degree = 5), data = my_df)
quintic_pred_train <- predict(quintic_mod, my_df)
poly_mod <- lm(Y ~ poly(X, degree = 15), data = my_df)
poly_pred_train <- predict(poly_mod, my_df)
get_MSE <- function(actual, pred){
mean((actual - pred)^2)
}
lin_mse_train <- get_MSE(my_df$Y, lin_pred_train)
quintic_mse_train <- get_MSE(my_df$Y, quintic_pred_train)
poly_mse_train <- get_MSE(my_df$Y, poly_pred_train)Now, we can compute the training MSE for these models:
model MSE
1 Linear 0.677
2 Quintic 0.086
3 Poly 0.071
Best model?


Now, we can compute the test MSE for these models:
lin_mod <- lm(Y ~ X, data = my_df)
lin_pred <- predict(lin_mod, test_df)
quintic_mod <- lm(Y ~ poly(X, degree = 5), data = my_df)
quintic_pred <- predict(quintic_mod, test_df)
poly_mod <- lm(Y ~ poly(X, degree = 15), data = my_df)
poly_pred <- predict(poly_mod, test_df)
get_MSE <- function(actual, pred){
mean((actual - pred)^2)
}
lin_mse <- get_MSE(test_df$Y, lin_pred)
quintic_mse <- get_MSE(test_df$Y, quintic_pred)
poly_mse <- get_MSE(test_df$Y, poly_pred)Now, we can compute the test MSE for these models:
model MSE
1 Linear 1.281
2 Quintic 0.326
3 Poly 1.822
Best model?

| model | Train.MSE | Test.MSE |
|---|---|---|
| Linear | 0.677 | 1.281 |
| Quintic | 0.086 | 0.326 |
| Poly | 0.071 | 1.822 |

Suppose we consider a variety of model shapes to predict \(Y\), with each model of increasing flexibility / complexity.
The U-curve for test MSE is a result of competition between two sources of error in a model
Expected test MSE can be decomposed as the sum of 3 quantities: \[ \mathrm{E} \left[ ( y_0 - \hat{f}(x_0))^2 \right] = \left[\mathrm{Bias}(\hat{f}(x_0))\right]^2 + \mathrm{Var}(\hat{f}(x_0)) + \mathrm{Var}(\epsilon) \]
Here \(\mathrm{E} \left[ ( y_0 - \hat{f}(x_0))^2 \right]\) denotes expected test MSE at \(x_0\), if many models for \(f\) were built using a variety of random training data sets containing \(x_0\)
Total expected test MSE is obtained by averaging across all possible \(x_0\) in the test set.
A proof is given in Section 7.3 of The Elements of Statistical Learning.
To minimize \(\mathrm{MSE}\), we need to simultaneously minimize both variance and bias.

Q: What happens as we pick more complex models?
As complexity increases, we tend to “overfit” model to training data.
Bias decreases and variance increases
We want a sufficiently complex model that doesn’t overfit training data.