blackblack
picture picture

Ch 5.1.5: k-fold Cross-Validation for Classification

Lecture 15 - CMSE 381
Michigan State University
::
Dept of Computational Mathematics, Science /span> Engineering
Fri, Feb 20, 2026
Announcements

Last time:

This lecture:

Announcements:

Section 1 picture picture

Last time
Approximations of Test Error

Validation Set Diagram
showing the first validation
set split. Diagram showing
the second validation set
split. Diagram showing the
third validation set split. Diagram showing the fourth
validation set split. Diagram
showing the fifth validation
set split. Figure labeled
validation set for
comparison.
LOOCV Diagram showing
the first leave-one-out
cross-validation split. Diagram showing the
second leave-one-out
cross-validation split. Diagram showing the third
leave-one-out
cross-validation split. Diagram showing the final
leave-one-out
cross-validation split. Figure
using the auto data example
to show a fixed result with
no randomness across
repeated runs.
K-fold CV Diagram
showing the first split in
five-fold cross-validation. Diagram showing the
second split in five-fold
cross-validation. Diagram
showing the third split in
five-fold cross-validation. Diagram showing the fourth
split in five-fold
cross-validation. Diagram
showing the fifth split in
five-fold cross-validation. Second figure from the auto
data example.
Definition of k-fold CV

Diagram showing the first split in five-fold
cross-validation. Diagram showing the
second split in five-fold cross-validation. Diagram showing the third split in five-fold
cross-validation. Diagram showing the
fourth split in five-fold cross-validation. Diagram showing the fifth split in five-fold
cross-validation. Return
CV(k) = 1 k i=1kMSE i

Section 2 picture picture

CV for Classification
Setup: LOOCV

Diagram showing the first leave-one-out
cross-validation split. Diagram showing the
second leave-one-out cross-validation split. Diagram showing the third leave-one-out
cross-validation split. Diagram showing the fourth
leave-one-out cross-validation split. Diagram
showing the fifth leave-one-out cross-validation
split. Diagram showing the final leave-one-out
cross-validation split. Return
CV(n) = 1 n i=1nErr i
Setup: k-fold

Diagram showing the first split in five-fold
cross-validation. Diagram showing the
second split in five-fold cross-validation. Diagram showing the third split in
five-fold cross-validation. Diagram
showing the fourth split in five-fold
cross-validation. Diagram showing the
fifth split in five-fold cross-validation.

Return

CV(k) = 1 k i=1kErr i
Example on simulated data: Linear

Classification plot illustrating data
points and the Bayes decision
boundary.
Example on simulated data: Quadratic logistic regression

Classification plot showing data
points and the Bayes decision
boundary for a second example.
Example on simulated data: all the polynomials!

Classification plot comparing the Bayes
decision boundary and logistic regression
fits with different polynomial degrees.
Decide degree based on CV

Plot of training error, test error, and
10-fold cross-validation error versus model
degree, used to choose the degree.
Similar game for KNN

Plot of training error, test error, and
10-fold cross-validation error used to
choose the value of K in classification.
Coding - k-fold for penguin classification section

TL;DR

k-fold CV Diagram showing the first split in five-fold
cross-validation. Diagram showing the
second split in five-fold cross-validation. Diagram showing the third split in five-fold
cross-validation. Diagram showing the
fourth split in five-fold cross-validation. Diagram showing the fifth split in five-fold
cross-validation.
CV(k) = 1 k i=1kMSE i

Use k = 5 or 10 usually

k-fold CV for classification
Erri = I(yjŷj)
CV(k) = 1 k i=1kErr i
Next time

Screenshot of the course schedule for lectures 11 to 20.