小编Anu*_*ani的帖子

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

我已经为 light 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)

Run Code Online (Sandbox Code Playgroud)

我预计它会运行 1000 次或更短的迭代,但它运行了 25 次,因为对数损失没有改善,但 f1 指标正在改善。

python machine-learning data-science lightgbm

3
推荐指数
1
解决办法
1312
查看次数

标签 统计

data-science ×1

lightgbm ×1

machine-learning ×1

python ×1