Cross-validation and GridSearchCV in scikit-learn, step by step
9 steps · about 3 h 15 min · Intermediate
- 3.1. Cross-validation: evaluating estimator performance (doc, scikit-learn documentation, 30 min)
Start with the official explanation of why a single split misleads and how k-fold averages scores.
- Cross Validation Using K-Fold With Scikit Learn (tutorial, GeeksforGeeks, 15 min)
A short runnable example of KFold and cross_val_score to make the idea concrete.
- Scikit-learn Cross Validation: Master K-Fold and Stratified Techniques (article, Sam Austin AI, 15 min)
Shows why StratifiedKFold and shuffling matter when classes are imbalanced.
- Set and get hyperparameters in scikit-learn (tutorial, Inria scikit-learn course, 15 min)
Teaches what a hyperparameter is and how to try values by hand before automating it.
- How to Tune Hyperparameters with GridSearchCV in scikit-learn (tutorial, Dewiride, 20 min)
Your first GridSearchCV run, with best_params_, best_score_ and cv_results_ explained.
- 3.2. Tuning the hyper-parameters of an estimator (doc, scikit-learn documentation, 35 min)
The reference for param_grid, distributions, scoring, refit and successive halving, once you have used the basics.
- Tuning Pipelines with GridSearchCV in scikit-learn (tutorial, CodeSignal Learn, 20 min)
Adds preprocessing to the search with the step__param syntax, which keeps scaling inside each fold and avoids leakage.
- Evaluation and hyperparameter tuning (tutorial, Inria scikit-learn course, 20 min)
Explains why the best grid-search score is optimistic and how an outer loop fixes that.
- Nested versus non-nested cross-validation (interactive, scikit-learn documentation, 25 min)
Run the official example to see the optimism gap between non-nested and nested CV for yourself.