I want to be able to save GridSearchCV output to file while running.
GridSearchCV(XGBClassifier(), tuned_parameters, cv=cv, n_jobs=-1, verbose=10)
This is an example for an output:
    Fitting 1 folds for each of 200 candidates, totalling 200 fits
    [Parallel(n_jobs=-1)]: Using backend with 4 concurrent workers.
    [CV] colsample_bytree=0.7, learning_rate=0.05, max_depth=4, n_estimators=300, subsample=0.7  
    [CV] colsample_bytree=0.7, learning_rate=0.05, max_depth=4, n_estimators=300, subsample=0.7 
score=0.645, total= 6.3min
    [Parallel(n_jobs=-1)]: Done   1 tasks      | elapsed:  6.3min
I managed to save the first line and the Parallel lines, but no matter what I tried, I couldn't save the lines that start with [CV]. I want to save those lines so if the program will fail, I could at least see part of the results.
I tried the solutions from here
sys.stdout = open('file', 'w')
and:
with open('help.txt', 'w') as f:
    with redirect_stdout(f):
        print('it now prints to `help.text`')
This solution (that is also referring to this solution) also didn't work:
class Tee(object):
    def __init__(self, *files):
        self.files = files
    def write(self, obj):
        for f in self.files:
            f.write(obj)
            f.flush() # If you want the output to be visible immediately
    def flush(self) :
    for f in self.files:
        f.flush()
And tried this monkey-patch as the author called it, but is also just saved the "Parallel" lines.
(Just to emphasize, the codes above are just a glimpse of the proposed solutions, when I tried them, I took all relevant code).
Is there a way to save ALL output?
 
     
    