Why Use Cross-Validation? — Interview Answer — ML Technical Interview Questions & Answers

Model answer covering more reliable performance estimates.

Why Use Cross-Validation? — Interview Answer

  • Say this: “A single split can be lucky. k-fold CV rotates the hold-out fold and averages. I use it to pick models and knobs. I still keep a final test if I can.”
  • Mention Pipeline so preprocessing sits inside each fold. Time data: TimeSeriesSplit.
  • cv=5 is a default you can defend. Nested CV if they go advanced (tuning + unbiased estimate).
  • Trap: CV after leaking the scaler on all X. Trap: random folds on a time series.

Technical Interview Tip: k exams, mean mark. Preprocess inside the loop.

Code Examples for Why Use Cross-Validation? — Interview Answer

Why Use Cross-Validation? — Interview Answer — working example

# Holdout split (sklearn: train_test_split). Pure Python for the lab:
X = [[0], [1], [2], [3], [4], [5], [6], [7], [8], [9]]
y = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1]
cut = int(0.8 * len(X))
X_train, X_test = X[:cut], X[cut:]
y_train, y_test = y[:cut], y[cut:]
print(len(X_train), len(X_test))
print(y_test)

# k-fold idea: rotate the held-out fold; average scores

Why Use Cross-Validation? — Interview Answer — hold out test data so you measure generalization. Cross-validation rotates folds for a stabler estimate.

How to Explain Why Use Cross-Validation? — Interview Answer to an Interviewer

Why CV?

Less luck than one split Better estimate

Leak example?

Scaler fit on all rows before CV