def nested_cv(xyinner_cvouter_cvclassifierparameter_grid)outer_scores [for each split of the data in the outer cross-validation (split method returns indicesfor training_samplestest_samples in outer_cv split(xy)find best parameter using inner cross-validation best_parms {best_score -np inf iterate over parameters for parameters in parameter_gridaccumulate score over inner splits cv_scores [iterate over inner cross-validation for inner_traininner_test in inner_cv splitx[training_samples] [training_samples])build classifier given parameters and training data clf classifier(**parametersclf fit( [inner_train] [inner_train]evaluate on inner test set score clf score( [inner_test] [inner_test]cv_scores append(scorecompute mean score over inner folds mean_score np mean(cv_scoresif mean_score best_scoreif better than so farremember parameters best_score mean_score best_params parameters build classifier on best parameters using outer training set clf classifier(**best_paramsclf fit( [training_samples] [training_samples]evaluate outer_scores append(clf score( [test_samples] [test_samples])return np array(outer_scoresnowlet' run this function on the iris datasetin[ ]from sklearn model_selection import parametergridstratifiedkfold scores nested_cv(iris datairis targetstratifiedkfold( )stratifiedkfold( )svcparametergrid(param_grid)print("cross-validation scores{}format(scores)out[ ]cross-validation scores parallelizing cross-validation and grid search while running grid search over many parameters and on large datasets can be computationally challengingit is also embarrassingly parallel this means that building model evaluation and improvement