# 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
{"ft_lang_label":"__label__en","ft_lang_prob":0.8759553,"math_prob":0.9454495,"size":828,"snap":"2023-14-2023-23","text_gpt3_token_len":211,"char_repetition_ratio":0.13349515,"word_repetition_ratio":0.120567374,"special_character_ratio":0.25483093,"punctuation_ratio":0.08383234,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.985035,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-06-01T09:50:28Z\",\"WARC-Record-ID\":\"<urn:uuid:93a7594b-0b35-4ae4-85d3-268916aeaaa1>\",\"Content-Length\":\"7076\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:6cbfe923-0ac8-4648-84c1-cfe0a50a643f>\",\"WARC-Concurrent-To\":\"<urn:uuid:1cc69e89-a83e-4665-8670-a42bf955acef>\",\"WARC-IP-Address\":\"172.67.140.24\",\"WARC-Target-URI\":\"https://yihui.org/animation/example/cv-ani/\",\"WARC-Payload-Digest\":\"sha1:WYFLZZG4JGQJU32AA6U277ED3USDEGT6\",\"WARC-Block-Digest\":\"sha1:QYDIYTUDMQ3QBKMVRMTALRZE5KSTIWHT\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-23/CC-MAIN-2023-23_segments_1685224647639.37_warc_CC-MAIN-20230601074606-20230601104606-00544.warc.gz\"}"}