blackblack
picture picture

Ch 5.1.1-2: Leave One Out Cross-validation

Lecture 12 - CMSE 381
Michigan State University
::
Dept of Computational Mathematics, Science /span> Engineering
Fri, 2/13, 2026
Announcements

Last time:

Announcements:

Screenshot of the course schedule fromlectures 11 to 20.
Covered in this lecture

Sectionย 1 picture picture

Validation set
Whatโ€™s the problem?

Training Error vs Testing Error

Training Error
Testing Error
Throw-back

Plot on left is scatter plot for simulated close to linear data with three different fits of varying
flexibility. Plot on right shows the training and testing MSE as a function of flexibility

Model tradeoffs

Prediction error versus model complexity. One curve shows the training sample error, while another
curve shows the test sample error.
Validation set approach

A horizontal bar representing data points with random chunks colored as either red (training set) or
yellow (test set).

Example with the auto data

PIC

Predicting ๐š–๐š™๐š using ๐š‘๐š˜๐š›๐šœ๐šŽ๐š™๐š˜๐š ๐šŽ๐š›:

๐š–๐š™๐š = ฮฒ0 + ฮฒ1๐š‘๐š™ + ฮฒ2๐š‘๐š™2 + โ‹ฏ + ฮฒ p๐š‘๐š™p
Rinse and repeat

A horizontal bar representing data points with random chunks colored as either red (training set) or
yellow (test set). A horizontal bar representing data points with random chunks colored as either red
(training set) or yellow (test set). A horizontal bar representing data points with random chunks
colored as either red (training set) or yellow (test set). A horizontal bar representing data points with
random chunks colored as either red (training set) or yellow (test set). A horizontal bar representing
data points with random chunks colored as either red (training set) or yellow (test set).

Again example with auto data

Mean squared error versus degree of
polynomial. Multiple curves corresponding
to different validation sets are shown.
Coding example in jupyter notebook

Sectionย 2 picture picture

Leave-One-Out Cross-Validation (LOOCV)
The idea

A horizontal bar representing data points with a yellow square (test set) at the zeroth position of the
bar with the rest of the bar red (training set) A horizontal bar representing data points
with a yellow square (test set) at the first position of the bar with the rest of the bar red
(training set) A horizontal bar representing data points with a yellow square (test set) at
the second position of the bar with the rest of the bar red (training set) A horizontal bar
representing data points with a yellow square (test set) at the third position of the bar with the
rest of the bar red (training set) A horizontal bar representing data points with a yellow
square (test set) at the fourth position of the bar with the rest of the bar red (training set) โ‹ฎ A
horizontal bar representing data points with a yellow square (test set) at last, rightmost position of the
bar with the rest of the bar red (training set)
The idea in mathy words

Return the score:

CV(n) = 1 nโˆ‘ i=1nMSE i
Again example with auto data

Mean squared error versus degree of
polynomial for LOOCV.
Do the LOOCV coding section

LOOCV Pros and Cons

Advantages:

Disadvantages:

TL;DR

Validation set A horizontal
bar representing data points
with random chunks colored
as either red (training set)
or yellow (test set). A
horizontal bar representing
data points with random
chunks colored as either red
(training set) or yellow (test
set). A horizontal bar
representing data points
with random chunks colored
as either red (training set)
or yellow (test set). A
horizontal bar representing
data points with random
chunks colored as either red
(training set) or yellow (test
set). A horizontal bar
representing data points
with random chunks colored
as either red (training set)
or yellow (test set).
LOO-CV A horizontal bar
representing data points
with a yellow square (test
set) at the zeroth position
of the bar with the rest of
the bar red (training set) A
horizontal bar representing
data points with a yellow
square (test set) at the first
position of the bar with the
rest of the bar red (training
set) A horizontal bar
representing data points
with a yellow square (test
set) at the second position
of the bar with the rest of
the bar red (training set) โ‹ฎ A horizontal bar
representing data points
with a yellow square (test
set) at last, rightmost
position of the bar with the
rest of the bar red (training
set)
LOO-CV Score
CV(n) = 1 nโˆ‘ i=1nMSE i
Next time

Screenshot of the course schedule from lectures 11 to 20.