I'm trying to plot MAE and RMSE from the XGboost model results. First I used gridsearchcv to find params then I fit the model and set eval_metrics to be printed out when fitting the model:
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)
I get correct result of this fit:
[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
However I tried accessing those values in order to create a plot but I get the following error:
myModel.evals_result()
AttributeError: 'GridSearchCV' object has no attribute 'evals_result'
How can I access those values?
You can create a result dict then pass it to fit
progress = dict()
history=myModel.fit(X_train, y_train, evals_result=progress eval_metric=eval_metric, eval_set=eval_set)
print(progress)