KatInterview

Cross-Validation Folds: Choosing k and Spotting Bad Estimates

Machine LearningModel answer
MediumModel answerMachine Learningcross-validationbias-variancedata-leakage

Last updated

Describe how k-fold cross-validation works, how the choice of k shifts bias, variance and cost, and which situations make a cross-validated score overly optimistic or unreliable.

You are evaluating a supervised model and want a trustworthy estimate of how well it will perform on unseen data.

Answer the following as you would in a technical conversation about machine learning fundamentals:

  1. Walk through the k-fold cross-validation procedure from start to finish. What exactly does the final number estimate?
  2. How does the choice of k affect the bias of the estimate, its variance, and the computational cost? Where do common values such as 5 and 10 fit, and what about leave-one-out?
  3. Describe the situations in which a cross-validated score can be misleading. Make sure you cover leakage, temporal ordering, grouped or duplicated records, and class imbalance, and say what you would do about each.

Be concrete: give small examples, say which metrics or splitters you would use, and mention any trade-offs you would weigh in practice.

Hints

Hint 1

Think about what fraction of the data each fold model is trained on, and how that compares with the model you eventually deploy.

Hint 2

As k grows, the training sets of different folds overlap more. Ask what that does to the correlation between fold scores, and therefore to the variance of their average.

Hint 3

For each failure mode, ask whether information from the validation rows could reach training: through preprocessing fitted on all data, through the same entity appearing on both sides, through future data predicting the past, or through selecting the best of many configurations on the same folds.