Cross-validation Folds
Partition indices without loss or overlap. Earlier folds receive the remainder; every validation item is excluded from its training fold.
indices = list(range(5))
validation = indices[:3]
training = indices[3:]
print(training, validation)From arithmetic to an experiment
Partition indices without loss or overlap. Earlier folds receive the remainder; every validation item is excluded from its training fold. The trace reads the local variables of your function as it executes. Change one input or parameter, predict the result, then run the checks again. A small deterministic example makes arithmetic mistakes easier to locate than a long training run. State the shape and meaning of the returned value before coding. Keep preprocessing, evaluation and model updates in their proper order, and examine the boundary case in each check. The companion lab lets you replay intermediate values while the same algorithm runs.
Your task
folds(n, k) returns k (training_indices, validation_indices) pairs with consecutive validation blocks. 1 <= k <= n. Put extra items in the earliest folds.
The explanation opens here once every check passes.