【发布时间】:2021-12-07 04:14:51
【问题描述】:
我正在使用 LightGBM,我需要实现一个损失函数,当预测低于目标值时,它会在训练期间给予惩罚。换句话说,我认为低估比高估要糟糕得多。我发现这个建议正好相反:
def custom_asymmetric_train(y_true, y_pred):
residual = (y_true - y_pred).astype("float")
grad = np.where(residual<0, -2*10.0*residual, -2*residual)
hess = np.where(residual<0, 2*10.0, 2.0)
return grad, hess
def custom_asymmetric_valid(y_true, y_pred):
residual = (y_true - y_pred).astype("float")
loss = np.where(residual < 0, (residual**2)*10.0, residual**2)
return "custom_asymmetric_eval", np.mean(loss), False
https://towardsdatascience.com/custom-loss-functions-for-gradient-boosting-f79c1b40466d)
如何根据我的目的修改它?
【问题讨论】:
标签: python machine-learning xgboost loss-function lightgbm