为什么这里print不打印?
def XGTSearch(X, y):
print("Parameter optimization")
n_estimators = [50, 100, 200, 400,600,800]
max_depth = [2, 4, 5,6,7, 8]
learning_rate = [0.0001, 0.001, 0.01, 0.05, 0.1, 0.2]
param_grid = dict(max_depth=max_depth, n_estimators=n_estimators, learning_rate=learning_rate)
print("param_grid:",param_grid)
xgb_model = XGBRegressor(objective='reg:squarederror')
kfold = TimeSeriesSplit(n_splits=5).get_n_splits([X, y])
fit_params = {"eval_metric": "rmse"}
grid_search = GridSearchCV(xgb_model, param_grid, verbose=1, fit_params=fit_params, cv=kfold)
grid_result = grid_search.fit(X, y)
# summarize results
print("Best: %f using %s" % (grid_result.best_score_, grid_result.best_params_))
means = grid_result.cv_results_['mean_test_score']
stds = grid_result.cv_results_['std_test_score']
params = grid_result.cv_results_['params']
for mean, stdev, param in zip(means, stds, params):
print("%f (%f) with: %r" % (mean, stdev, param))
rgs = GridSearchCV(xgb_model, param_grid)
rgs.fit(X, y)
print(rgs.fit(X, y), flush=True)
return mean, stdev, param, grid_result