K-Fold Cross-Validation

noun

say it: “KAY FOHLD KRAWS val-ih-DAY-shun” /ˈkeɪ ˈfoʊld ˈkrɔs ˌvæləˈdeɪʃən/

A form of cross-validation that divides the data into k equal parts and tests on each part in turn while training on the others.

What is k-fold cross-validation?

K-fold cross-validation splits the rows into k equal parts, called folds, then trains k times: each time it tests on one fold and trains on the rest, so every row is tested exactly once. With k=5 you get five scores to average. scikit-learn's KFold makes the folds.

from sklearn.model_selection import KFold
days = list(range(10))
for train, test in KFold(n_splits=5).split(days):
    print(test)   # [0 1], then [2 3], [4 5], [6 7] and [8 9]

In a sentence

  • “K-fold cross-validation trained the model five times on four-fifths of the data.”
  • “With k-fold cross-validation and k=5, each home was in the test fold exactly once.”

Level: Journeyman · More AI Basics terms at this level

Updated