GridSearchCV - save result each iteration
Asked Answered
T

1

9

I'm using GridSearchCV, and after each iteration I want to save the clf.cv_results_ property to a file, (just in case that the process will crash in the middle).

I tried looking for a solution but I just couldn't figure it out.

Any help will be appreciated.

Trivalent answered 2/1, 2018 at 8:54 Comment(1)
please add some sample code and some elements of your dataset in order to helpKathaleenkatharevusa
K
7

One of the ways to do it is to set the verbose parameter of your grid search to an integer higher than 0 like 10 or more, it will print the result for each iteration to the console.

With this, your output should be print or logged to your console, Then follow the answer to this or this question to see how to put the logged result to a file.

Basically, put this before running the GridSearch:

import sys
old_stdout = sys.stdout

log_file = open("message.log","w")

sys.stdout = log_file

Then after running your GridSearch, you should close all resources with this:

sys.stdout = old_stdout
log_file.close()
Kathaleenkatharevusa answered 2/1, 2018 at 9:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.