What is cross-validation and why use it?
Assesses fundamental understanding of Machine Learning conventions, runtime behavior, and memory/performance considerations.
Hiring managers look for precision, avoidance of ambiguous jargon, and ability to explain trade-offs under real production conditions.
Cross-validation repeatedly splits data into training and validation folds to estimate how well a model generalizes. In k-fold, the data is split into k parts; the model trains on k-1 and validates on the remaining one, rotating so every point is validated once. The average score is the estimate.
from sklearn.model_selection import cross_val_score
scores = cross_val_score(model, X, y, cv=5, scoring="roc_auc")
Variants: stratified k-fold preserves class ratios for imbalanced data; grouped k-fold keeps all rows of one entity together to avoid leakage; time series split respects temporal order.
Use it for model selection, hyperparameter tuning and comparing algorithms. Pitfalls: preprocessing such as scaling or SMOTE must be fit inside each fold via a pipeline, otherwise information leaks and the score is optimistic. Keep a separate untouched test set for the final estimate.
Candidate Response Strategy & Interview Tips
- Start with a concise one-sentence summary: Deliver a direct, confident answer first before expanding into nuances.
- Demonstrate real-world trade-offs: Discuss where this approach excels and when you would avoid it in production systems.
- Discuss complexity & edge cases: Proactively explain time/space complexity or boundary conditions (null values, scale limits).
- Prepare for interviewer follow-ups: Technical hiring panels frequently probe deeper into concurrency, backward compatibility, or alternative libraries.