如果我在管道上使用GridsearchCV,如何在Xgboost中使用model.evals_result?

问题描述

我正在使用XGBoost回归器,并且如果我在不仅包含模型的管道上使用gridsearchcv,还存在有关如何使用model.evals_result()的问题。

# Define pipeline with feature-selection
pipe_xgb = Pipeline([("selector",SelectKBest(f_regression)),("xgb_reg",xgboost.XGBRegressor(objective ="reg:squarederror",eval_metric="rmse",early_stopping_rounds=10,random_state=42))])
# grid search on a set search space
xgb_cv = gridsearchcv(pipe_xgb,search_space_xgb,cv=10,verbose=0)
xgb_cv = xgb_cv.fit(X_train,y_train)

# get best pipeline as well as model
best_xgb = xgb_cv.best_estimator_
best_model = xgb_cv.best_estimator_[1]

best_model.evals_result()

但是,这给了我

AttributeError: 'XGBRegressor' object has no attribute 'evals_result_'

如果我不是使用管道,而是仅使用gridsearch搜索模型参数,那么

best_xgb.evals_result()

会工作。有什么想法吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)