crossval() — Cross-validation

Score a model on data it never trained on to catch overfitting.

crossval(model, data, K)

Key idea

Definition

how many folds (parts) you split into
the held-out test part
the average held-out error

In plain words

Do not grade the model on the questions it studied. Hide some data, train, then test on the hidden part, and rotate so every part gets a turn.

Where you'd use it

Frequently asked questions

Why cross-validate?
To estimate performance on unseen data and avoid overfitting to one lucky split.
Where should scaling happen?
Inside each fold — fitting it on all the data leaks test information.