kfold kfold(n_splits= print("cross-validation scores:\ {}formatcross_val_score(logregiris datairis targetcv=kfold))out[ ]cross-validation scores remembereach fold corresponds to one of the classes in the iris datasetand so nothing can be learned another way to resolve this problem is to shuffle the data instead of stratifying the foldsto remove the ordering of the samples by label we can do that by setting the shuffle parameter of kfold to true if we shuffle the datawe also need to fix the random_state to get reproducible shuffling otherwiseeach run of cross_val_score would yield different resultas each time different split would be used (this might not be problembut can be surprisingshuffling the data before splitting it yields much better resultin[ ]kfold kfold(n_splits= shuffle=truerandom_state= print("cross-validation scores:\ {}formatcross_val_score(logregiris datairis targetcv=kfold))out[ ]cross-validation scores leave-one-out cross-validation another frequently used cross-validation method is leave-one-out you can think of leave-one-out cross-validation as -fold cross-validation where each fold is single sample for each splityou pick single data point to be the test set this can be very time consumingparticularly for large datasetsbut sometimes provides better estimates on small datasetsin[ ]from sklearn model_selection import leaveoneout loo leaveoneout(scores cross_val_score(logregiris datairis targetcv=looprint("number of cv iterations"len(scores)print("mean accuracy{ }format(scores mean())out[ ]number of cv iterationsmean accuracy cross-validation