我正在尝试从XGboost模型结果中绘制MAE和RMSE。 首先,我使用gridsearchcv查找参数 然后我拟合模型并设置eval_metrics以在拟合模型时打印出来:
DefaultRouter
我得到了适合的正确结果:
myModel = GridSearchCV(estimator=XGBRegressor(
learning_rate=0.01,
n_estimators=500,
max_depth=5,
min_child_weight=5,
gamma=0,
subsample=0.8,
colsample_bytree=0.8,
eval_metric ='mae',
reg_alpha=0.05
),
param_grid = param_search,
cv = TimeSeriesSplit(n_splits=5),n_jobs=-1
)
#Fit model
eval_set = [(X_train, y_train), (X_test, y_test)]
eval_metric = ["rmse","mae"]
history=myModel.fit(X_train, y_train, eval_metric=eval_metric, eval_set=eval_set)
但是我尝试访问这些值以创建图,但是出现以下错误:
[0] validation_0-rmse:7891 validation_0-mae:7791.42 validation_1-rmse:6465.99 validation_1-mae:6465.52
[1] validation_0-rmse:7813.98 validation_0-mae:7714.55 validation_1-rmse:6398.87 validation_1-mae:6398.4
如何获取这些值?
答案 0 :(得分:0)
您可以创建结果字典,然后将其传递以适合
progress = dict()
history=myModel.fit(X_train, y_train, evals_result=progress eval_metric=eval_metric, eval_set=eval_set)
print(progress)