cv.ani()

Demonstration of the k-fold Cross Validation

Yihui Xie & Lijia Yu 2017-04-04

This function uses rectangles to illustrate the \(k\) folds and mark the test set and the training set with different colors.

Briefly speaking, the process of cross-validation is just to split the whole data set into several parts and select one part as the test set and the rest parts as the training set.

The computation of sample sizes is base on kfcv.

This is a naive demonstration for the k-fold cross validation. The k rectangles in the plot denote the k folds of data. Each time a fold will be used as the test set and the rest parts as the training set.

library(animation)
ani.options(interval = 1, nmax = 15)
cv.ani(main = "Demonstration of the k-fold Cross Validation", bty = "l")

plot of chunk demo-a

## leave-one-out CV
cv.ani(x = runif(15), k = 15)

plot of chunk demo-b