m0_61493924 2022-09-07 10:57 采纳率: 100%

# 这一段的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
``````
• 写回答

#### 问题事件

• 已结题 9月15日
• 已采纳回答 9月8日
• 赞助了问题酬金10元 9月7日
• 创建了问题 9月7日

#### 悬赏问题

• ¥30 关于#网络安全#的问题：非对称加密验证
• ¥20 关于线性代数里施密特正交化和QR分解的疑问
• ¥15 matlab超类包含解析错误
• ¥15 python拖拽文件问题