Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

GridSearchCV for estimating optimal tuning parameter

I am facing key error : 0 as a problem in these codes of lines

grid.cv_results_[0].parameters

print(grid.cv_results_[0].cv_validation_scores)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

print(grid.cv_results_[0].mean_validation_scores)

>Solution :

GridSearchCV's cv_results_ returns a dictionary. Therefore you can’t access it via index. For example:

svc = svm.SVC()
grid = GridSearchCV(svc, parameters)
grid.fit(data, target)
print(grid.cv_results_.keys())

Output will be:

['mean_fit_time', 'mean_score_time', 'mean_test_score',...
 'param_C', 'param_kernel', 'params',...
 'rank_test_score', 'split0_test_score',...
 'split2_test_score', ...
 'std_fit_time', 'std_score_time', 'std_test_score']

You can access cv_results_ items like:

grid.cv_results_['params'] ##instead of grid.cv_results_[0].parameters
grid.cv_results_['std_test_score'] ##for test scores
grid.cv_results_['mean_test_score'] ##for mean test scores
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading