python - 轻型 GBM 提前停止不适用于自定义指标
问题描述
我已经为轻型 gbm 使用了一个自定义指标,但提前停止了日志丢失的工作,这是目标函数,我该如何解决这个问题或更改提前停止以适用于 eval 指标。
def evaluate_macroF1_lgb(truth, predictions):
pred_labels = predictions.reshape(len(np.unique(truth)),-1).argmax(axis=0)
f1 = f1_score(truth, pred_labels, average='macro')
return ('macroF1', f1, True)
lg = LGBMClassifier(n_estimators=1000)
lg.fit(x_train,y_train,eval_set=(x_test,y_test),eval_metric=evaluate_macroF1_lgb,early_stopping_rounds=25)
我预计它会运行 1000 次或更少迭代,但它运行了 25 次,因为日志损失没有改善,但 f1 指标正在改善。
解决方案
更新
我找到了一个解决方案,我们可以在 LGBM 分类器中设置 metric="custom" 然后它将使用 eval 指标。
lg = LGBMClassifier(n_estimators=1000,metric="custom")
推荐阅读
- amazon-s3 - 如何在 AWS Glue 脚本中将数据写入 S3 时添加不在动态框架中的分区
- machine-learning - 我可以从 lightgbm 或 xgboost 模型中采样或选择单个树吗?
- reactjs - 如何获取 ORDER 和 OrderItems 的值
- swift - AVAsset.LoadValuesAsynchronously 0 轨道在完成处理程序与 m3u8 URL
- java - 如何添加 O(N) 和 O(M)?
- django - geopy 返回“Civitas Vaticana”字符串而不是 django 中的实际城市名称
- javascript - 如何通过重定向更改选定的选项卡
- vue.js - 如何在 vuetify 卡中使画布响应
- c - 是否可以使用 tee 捕获标准输入?
- javascript - 如何在Angular 11中路由到PDF文件