Block 78: Cross-Validation & Hyperparameter Tuning
Use cross-validation for reliable estimates and grid search to tune models.
Concepts
- cross_val_score() with cv=5
- Why single train/test split can be misleading
- GridSearchCV and RandomizedSearchCV
- Best params and best score
Code Examples
See exercise below.
Exercise
Use 5-fold cross-validation on 3 models. Compare mean and std of scores. Run GridSearchCV on KNN over n_neighbors=[1,3,5,7,9]. Print best k and accuracy.
Homework
When would you prefer RandomizedSearchCV over GridSearchCV? Give a practical example. Friday