By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
Model validation is the systematic way we estimate how a machine‑learning model will perform on unseen data. Cross‑validation (k‑fold, stratified, time‑series) is a family of techniques that repeatedly split the data into training and validation folds so we can measure generalisation, tune hyper‑parameters, and guard against over‑fitting. In a churn‑prediction project for a telecom, proper validation tells you whether the model you built today will still flag the right customers next month, rather than just memorising the quirks of the current dataset.
cross_val_score
python from sklearn.model_selection import cross_val_score scores = cross_val_score(model, X, y, cv=5, scoring='roc_auc')
StandardScaler
Pipeline
OneHotEncoder
X
y
StratifiedKFold
TimeSeriesSplit
pipe = Pipeline([ ('scaler', StandardScaler()), ('clf', RandomForestClassifier(random_state=42)) ]) `` 4. Run Cross‑Validation – Usecross_val_score(orcross_validatefor multiple metrics) with the chosen splitter. Record mean ± std. 5. Hyper‑parameter Tuning – Wrap the pipeline inGridSearchCVorRandomizedSearchCV` inside the CV splitter (nested CV) to avoid leakage. 6. Final Evaluation – After selecting the best hyper‑parameters, fit on the full training set, predict on the held‑out test set, and report the unbiased test metric.
`` 4. Run Cross‑Validation – Use
(or
for multiple metrics) with the chosen splitter. Record mean ± std. 5. Hyper‑parameter Tuning – Wrap the pipeline in
or
Scenario: Your churn model shows high variance across folds (std > 0.1 in AUC). Answer: Increase regularisation (e.g., max_depth for trees, C for logistic regression) or use a more robust ensemble (e.g., BaggingClassifier). Why: Regularisation reduces model complexity, lowering variance.
max_depth
C
BaggingClassifier
Scenario: You have a binary classification problem with 1 % positives. Which CV strategy and metric should you prioritize? Answer: Use StratifiedKFold and evaluate with AUC‑PR (Precision‑Recall) rather than ROC‑AUC. Why: Stratification keeps the rare class represented; PR‑AUC is more informative for extreme imbalance.
Scenario: After a grid search, you obtain the best hyper‑parameters on the validation folds, but the test set performance drops sharply. Answer: You likely suffered from validation leakage; redo tuning with nested CV or a fresh validation split.
n_splits=5
scoring='neg_mean_squared_error'
-score
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.