首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在Light GBM管道中使用eval_result方法?

如何在Light GBM管道中使用eval_result方法?
EN

Stack Overflow用户
提问于 2021-08-16 15:30:47
回答 2查看 119关注 0票数 0

我使用了ligth GBM算法,并创建了一个类似于以下内容的管道:

代码语言:javascript
运行
复制
#model definition
model_lgbm = LGBMClassifier(
                #training loss
                objective='binary', # write a custom objective function that is cost sensitive
                n_estimators =  params['n_estimators'],
                max_depth =  params['max_depth'])

#pipeline instantiation using a previoulsy defined feature engineering pipeline (it does scaling etc.)
model_pipeline_lgbm = Pipeline(steps=[('preprocessor', feature_pipe_lgbm),
                                      ('model_lgbm', model_lgbm),
                                     ])

#fit of feature pipeline and transformation of validation sets
feature_pipe_lgbm.fit(X_train, Y_train)

X_val_trans = feature_pipe_lgbm.transform(X_val)
X_train_trans = feature_pipe_lgbm.transform(X_train)

encoded_column_names = ['f{}'.format(i) for i in range(X_val_trans.shape[1])]
X_val_trans = pd.DataFrame(data=X_val_trans, columns=encoded_column_names, index=X_val.index)

X_train_trans = pd.DataFrame(
    data=X_train_trans, columns=encoded_column_names, index=X_train.index)

#definition of evaluation set and evaluation metric
eval_metric = "binary_logloss"
eval_set = [(X_train_trans, Y_train), (X_val_trans, Y_val)]

然后对管道进行拟合,并希望将评估结果存储在字典中,如此repo所示

代码语言:javascript
运行
复制
evals_result = {}
model_pipeline_lgbm.fit(X=X_train,
                        y=Y_train,
                        model_lgbm__eval_set=eval_set,
                        # validation loss
                        model_lgbm__eval_metric=eval_metric, #same here consider cost sensitvity
                        model_lgbm__early_stopping_rounds= params['early_stopping_patience'],
                        model_lgbm__evals_result=evals_result
                        )

但是,我收到以下错误:

代码语言:javascript
运行
复制
TypeError: fit() got an unexpected keyword argument 'evals_result'

您知道我需要在流水线的什么地方定义eval_results,这样我就可以调用它来创建绘图了吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-08-16 19:58:48

.fit调用之后,您应该能够通过LGBMClassifier访问它:

代码语言:javascript
运行
复制
model_pipeline_lgbm.fit(...)

model_pipeline_lgbm.steps['model_lgbm'].evals_result_
票数 1
EN

Stack Overflow用户

发布于 2021-08-17 10:17:33

谢谢@Berriel,你给了我丢失的信息。我只是没有正确访问管道步骤。最后,这个方法起作用了:

代码语言:javascript
运行
复制
model_pipeline_lgbm.steps[1][1].evals_result_
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68805525

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档