2026-10-20
Mini Project 2
Lab 5 (Linear Models)
Quiz 3: in class next Thursday October 29
Machine Learning: a broad term, coined in the 1950s, describing a set of inter-related techniques for extracting info from data
Supervised Learning: Modeling a specific response from “labeled” data. That is, we have a set of input-output pairs.
Unsupervised Learning: Approach to finding patterns where there is no clear response variable.
There are two things we can do with fitting a model:
Calculating a prediction is easy: Plug in your predictor variables into the formula defining the model to get the predicted response \(\hat{y}\)
Getting a good prediction is hard:
“All models are wrong, but some are useful”
Several steps to create a useful statistical model: parameter estimation, model selection, performance assessment, etc.
Doing all of this on the entire data we have available can lead to overfitting
To avoid overfitting, we split the data.
Consider a random sample of 1000 flights from NYC to Chicago in 2013. We want to create a model to predict arrival delay.
This finds the coefficients in the model \(y = \beta_0 + \beta_{hour} X_{hour} + \beta_{dep delay} X_{dep delay}\)
1 2 3 4 5 6
-9.759234 -13.193375 -15.259597 -14.309398 -20.313551 -6.659900
Plugs all of the TEST values of hour and dep_delay into the model above
We can compare the predicted values to the actual values:
Root Mean Square Error (RMSE) - for numerical response
\[ \text{RMSE} = \sqrt{\frac{\sum^{n}_{i=1}(y_i - \hat{y}_i)^2}{n}} \]
RMSE for Test Set:
Penalizes large errors more heavily (because error is squared), so it’s sensitive to outliers.
To give the number meaning, compare it to, say, the standard deviation in the arrival delays
The RMSE (15.8) is smaller than the standard deviation of the response variable (47.1), which is a good sign
Mean Absolute Error (MAE) - for numerical response
\[\text{MAE} = \frac{1}{n} \sum^{n}_{i=1}|y_i - \hat{y}_i|\]
MAE for Test Set:
# A tibble: 1 × 2
MSE1 MSE2
<dbl> <dbl>
1 15.854 15.844
# A tibble: 1 × 2
MAE1 MAE2
<dbl> <dbl>
1 12.031 12.046
Potential Problem with a single split into training/testing: you evaluated the model only once and you are not sure your good result is by luck or not
We can easily do this using cross validation
RLinear Regression
1000 samples
2 predictor
No pre-processing
Resampling: Cross-Validated (5 fold)
Summary of sample sizes: 800, 800, 800, 800, 800
Resampling results:
RMSE Rsquared MAE
19.0237 0.8312302 13.36263
Tuning parameter 'intercept' was held constant at a value of TRUE
If your model has hyperparameters, best to do it this way:
Withhold a portion of the data for testing, and then do cross-validation within the testing set
Note: Linear regression does not have hyperparameters, but we will discuss methods that do later in the course.
We extrapolate when we use the regression equation to produce a response value from an x-value that is outside the range of the observed x-values
Example: Relationship between year and diameter of a dinner plate.