which might make our results unstable and make us depend too much on this single split of the data we can go step furtherand instead of splitting the original data into training and test sets onceuse multiple splits of cross-validation this will result in what is called nested cross-validation in nested cross-validationthere is an outer loop over splits of the data into training and test sets for each of thema grid search is run (which might result in different best parameters for each split in the outer loopthenfor each outer splitthe test set score using the best settings is reported the result of this procedure is list of scores--not modeland not parameter setting the scores tell us how well model generalizesgiven the best parameters found by the grid as it doesn' provide model that can be used on new datanested crossvalidation is rarely used when looking for predictive model to apply to future data howeverit can be useful for evaluating how well given model works on particular dataset implementing nested cross-validation in scikit-learn is straightforward we call cross_val_score with an instance of gridsearchcv as the modelin[ ]scores cross_val_score(gridsearchcv(svc()param_gridcv= )iris datairis targetcv= print("cross-validation scores"scoresprint("mean cross-validation score"scores mean()out[ ]cross-validation scores mean cross-validation score the result of our nested cross-validation can be summarized as "svc can achieve mean cross-validation accuracy on the iris dataset"--nothing more and nothing less herewe used stratified five-fold cross-validation in both the inner and the outer loop as our param_grid contains combinations of parametersthis results in whopping models being builtmaking nested cross-validation very expensive procedure herewe used the same cross-validation splitter in the inner and the outer loophoweverthis is not necessary and you can use any combination of cross-validation strategies in the inner and outer loops it can be bit tricky to understand what is happening in the single line given aboveand it can be helpful to visualize it as for loopsas done in the following simplified implementationgrid search