gpt4 book ai didi

python - 轻型 GBM 提前停止不适用于自定义指标

转载 作者:行者123 更新时间:2023-11-30 09:42:21 27 4
gpt4 key购买 nike

我对 light gbm 使用了自定义指标,但提前停止了对数损失的工作,这是目标函数,我如何解决这个问题或更改提前停止以适用于评估指标。

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",然后它将使用评估指标。


lg = LGBMClassifier(n_estimators=1000,metric="custom")

关于python - 轻型 GBM 提前停止不适用于自定义指标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57222667/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com