How to print accuracy in each fold of Validation Dataset? and assign fold number to each row in the dataframe?

How to print the accuracy in each fold of a Validation Dataset ? And how can I assign the fold number to each row in the dataframe?

classifier = RandomForestRegressor(n_jobs = -1, criterion='mse')
clf = GridSearchCV(classifier, param_grid = tunedParameters,cv=10)
all_accuracies = cross_val_score(classifier, X=X_train, y=y_train, cv=10)
print(all_accuracies)


You're mixing up GridSearchCV and cross_val_score; you should only need to run one of them.

GridSearchCV will search through your hyperparameter space, for each combination using cross-validation and producing a score. You can access these scores through the attribute cv_results_.

cross_val_score has no hyperparameter search; it just scores using cross-validation. The output is a list of the individual fold scores.

If you've already used GridSearchCV, there's probably no reason to use cross_val_score. (After hyperparameter searching, you've seen and used all the data in that set, so the scores in cv_results_ are biased as would be the scores out of cross_val_score; if you need an unbiased estimate of performance, you'll need another test set (or nested cross-validation in the first place).)

If you want to keep track of which samples go in which fold, I think you need to use a cross-validation generator or iterable for the cv parameter instead of an integer. Then you can use that generator/iterable to also tell you which samples are in which fold.
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.2673906683921814, "perplexity": 1600.712285594928}, "config": {"markdown_headings": false, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.3, "absolute_threshold": 10, "end_threshold": 5, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2021-49/segments/1637964363157.32/warc/CC-MAIN-20211205100135-20211205130135-00122.warc.gz"}