如何解决如果我在管道上使用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 举报,一经查实,本站将立刻删除。