CS60050: Machine Learning
Sourangshu Bhattacharya
CROSS-VALIDATION
The test set method
Copyright © Andrew W. Moore
Slide 3
Good news:
Bad news:
The test set method
Copyright © Andrew W. Moore
Slide 4
Good news:
Bad news:
We say the “test-set estimator of performance has high variance”
LOOCV (Leave-one-out Cross Validation)
Copyright © Andrew W. Moore
Slide 5
x
y
For k=1 to R
1. Let (xk,yk) be the kth record
LOOCV (Leave-one-out Cross Validation)
Copyright © Andrew W. Moore
Slide 6
x
y
For k=1 to R
from the dataset
LOOCV (Leave-one-out Cross Validation)
Copyright © Andrew W. Moore
Slide 7
x
y
For k=1 to R
from the dataset
LOOCV (Leave-one-out Cross Validation)
Copyright © Andrew W. Moore
Slide 8
For k=1 to R
from the dataset
x
y
LOOCV (Leave-one-out Cross Validation)
Copyright © Andrew W. Moore
Slide 9
For k=1 to R
from the dataset
When you’ve done all points, report the mean error.
x
y
LOOCV (Leave-one-out Cross Validation)
Copyright © Andrew W. Moore
Slide 10
For k=1 to R
remove (xk,yk) from the dataset
remaining R-1
datapoints
error (xk,yk)
When you’ve done all points, report the mean error.
MSELOOCV
= 2.12
x
y
x
y
y
x
y
x
y
y
y
x
y
x
y
x
x
x
LOOCV for Quadratic Regression
Copyright © Andrew W. Moore
Slide 11
For k=1 to R
remove (xk,yk) from the dataset
remaining R-1
datapoints
error (xk,yk)
When you’ve done all points, report the mean error.
MSELOOCV
=0.962
x
y
x
y
y
x
y
x
y
y
y
x
y
x
y
x
x
x
LOOCV for Join The Dots
Copyright © Andrew W. Moore
Slide 12
For k=1 to R
remove (xk,yk) from the dataset
remaining R-1
datapoints
error (xk,yk)
When you’ve done all points, report the mean error.
MSELOOCV
=3.33
x
y
x
y
y
x
y
x
y
y
y
x
y
x
y
x
x
x
Which kind of Cross Validation?
Copyright © Andrew W. Moore
Slide 13
| Downside | Upside |
Test-set | Variance: unreliable estimate of future performance | Cheap |
Leave- one-out | Expensive. Has some weird behavior | Doesn’t waste data |
..can we get the best of both worlds?
k-fold Cross Validation
Copyright © Andrew W. Moore
Slide 14
x
y
Randomly break the dataset into k partitions (in our example we’ll have k=3 partitions colored Red Green and Blue)
k-fold Cross Validation
Copyright © Andrew W. Moore
Slide 15
x
y
Randomly break the dataset into k partitions (in our example we’ll have k=3 partitions colored Red Green and Blue)
For the red partition: Train on all the points not in the red partition. Find the test-set sum of errors on the red points.
k-fold Cross Validation
Copyright © Andrew W. Moore
Slide 16
x
y
Randomly break the dataset into k partitions (in our example we’ll have k=3 partitions colored Red Green and Blue)
For the red partition: Train on all the points not in the red partition. Find the test-set sum of errors on the red points.
For the green partition: Train on all the points not in the green partition.
Find the test-set sum of errors on the green points.
k-fold Cross Validation
Copyright © Andrew W. Moore
Slide 17
x
y
Randomly break the dataset into k partitions (in our example we’ll have k=3 partitions colored Red Green and Blue)
For the red partition: Train on all the points not in the red partition. Find the test-set sum of errors on the red points.
For the green partition: Train on all the points not in the green partition.
Find the test-set sum of errors on the green points.
For the blue partition: Train on all the
points not in the blue partition. Find the test-set sum of errors on the blue points.
k-fold Cross Validation
Copyright © Andrew W. Moore
Slide 18
x
y
Randomly break the dataset into k partitions (in our example we’ll have k=3 partitions colored Red Green and Blue)
For the red partition: Train on all the points not in the red partition. Find the test-set sum of errors on the red points.
For the green partition: Train on all the points not in the green partition.
Find the test-set sum of errors on the green points.
For the blue partition: Train on all the
points not in the blue partition. Find the test-set sum of errors on the blue points.
Then report the mean error
Linear Regression
MSE3FOLD=2.05
k-fold Cross Validation
Copyright © Andrew W. Moore
x
y
Randomly break the dataset into k partitions (in our example we’ll have k=3 partitions colored Red Green and Blue)
For the red partition: Train on all the points not in the red partition. Find the test-set sum of errors on the red points.
For the green partition: Train on all the points not in the green partition.
Find the test-set sum of errors on the green points.
For the blue partition: Train on all the
points not in the blue partition. Find the test-set sum of errors on the blue points.
Then report the mean error
Quadratic Regression
MSE3FOLD=1.11
Slide 33
k-fold Cross Validation
Copyright © Andrew W. Moore
Slide 20
x
y
Randomly break the dataset into k partitions (in our example we’ll have k=3 partitions colored Red Green and Blue)
For the red partition: Train on all the points not in the red partition. Find the test-set sum of errors on the red points.
For the green partition: Train on all the points not in the green partition.
Find the test-set sum of errors on the green points.
For the blue partition: Train on all the
points not in the blue partition. Find the test-set sum of errors on the blue points.
Then report the mean error
Joint-the-dots
MSE3FOLD=2.93
Which kind of Cross Validation?
Copyright © Andrew W. Moore
Slide 21
| Downside | Upside |
Test-set | Variance: unreliable estimate of future performance | Cheap |
Leave- one-out | Expensive. Has some weird behavior | Doesn’t waste data |
10-fold | Wastes 10% of the data. 10 times more expensive than test set | Only wastes 10%. Only 10 times more expensive instead of R times. |
3-fold | Wastier than 10-fold. Expensivier than test set | Slightly better than test- set |
R-fold | Identical to Leave-one-out | |
CV-based Model Selection
Copyright © Andrew W. Moore
Slide 22
•
Step 2: Whichever model class gave best CV score: train it
with all the data, and that’s the predictive model you’ll use.
Algorithm | TRAINERR | 10-FOLD-CV-ERR | Choice |
0 hidden units | | | |
1 hidden units | | | |
2 hidden units | | | ⌦ |
3 hidden units | | | |
4 hidden units | | | |
5 hidden units | | | |
CV-based Model Selection
Copyright © Andrew W. Moore
Slide 23
Algorithm | TRAINERR | 10-fold-CV-ERR | Choice |
K=1 | | | |
K=2 | | | |
K=3 | | | |
K=4 | | | ⌦ |
K=5 | | | |
K=6 | | | |
•
Step 2: Whichever model class gave best CV score: train it
with all the data, and that’s the predictive model you’ll use.
CV-based Model Selection
Copyright © Andrew W. Moore
Slide 24
These involve choosing the value of a real-valued parameter. What should we do?
Idea One: Consider a discrete set of values (often best to consider a set of values with exponentially increasing gaps, as in the K-NN example).
Idea Two: Compute
and then
do gradianet descent.
∂ Parameter
∂ LOOCV