I have a code
import sys
old_stdout = sys.stdout
log_file = open("cv.log","w")
sys.stdout = log_file
import xgboost as xgb
from sklearn.pipeline import Pipeline
from sklearn.datasets import make_classification
from sklearn.model_selection import GridSearchCV
X_train, y_train = make_classification(n_samples=2000)
params_str_dict = {"xgb__n_estimators": [10, 30], "xgb__max_depth": [50], "xgb__learning_rate": [0.5, 1], "xgb__objective": ["binary:logistic"]}
pipe = Pipeline(steps=[("xgb", xgb.XGBClassifier())])
model_GS = GridSearchCV(
estimator=pipe,
param_grid=params_str_dict,
n_jobs=-1,
cv=3,
verbose=3,
).fit(X_train, y_train)
sys.stdout = old_stdout
log_file.close()
When script has ended - in file i see
Fitting 3 folds for each of 4 candidates, totalling 12 fits
However, after 2 minutes, information about the cv show in the visual output. I think that's why it's not save to the file (it comes too late)
[CV 1/3] END xgb__learning_rate=0.5, xgb__max_depth=50, xgb__n_estimators=10, xgb__objective=binary:logistic;, score=0.964 total time= 0.1s
[CV 2/3] END xgb__learning_rate=0.5, xgb__max_depth=50, xgb__n_estimators=10, xgb__objective=binary:logistic;, score=0.951 total time= 0.1s
[CV 3/3] END xgb__learning_rate=0.5, xgb__max_depth=50, xgb__n_estimators=10, xgb__objective=binary:logistic;, score=0.961 total time= 0.1s
[CV 1/3] END xgb__learning_rate=1, xgb__max_depth=50, xgb__n_estimators=10, xgb__objective=binary:logistic;, score=0.973 total time= 0.1s
I use Visual Studio Code with Jupyter Kernel but in Python is the same problem.