【问题标题】:Asymmetric Function for Loss损失的不对称函数
【发布时间】: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


    【解决方案1】:

    我相信这个函数是你想要做出改变的地方。

    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
    

    计算出loss的那条线有比较。

    loss = np.where(residual < 0, (residual**2)*10.0, residual**2) 
    

    当residual小于0时,loss为residual^2 * 10 其中大约为 0 时,损失只是重新分配^2。

    因此,如果我们将小于改为大于。这将翻转倾斜。

    loss = np.where(residual > 0, (residual**2)*10.0, residual**2) 
    

    【讨论】:

    • 感谢您的帮助,我需要进行更改,尤其是在第一个功能(培训功能)中。不幸的是,从少到大似乎不起作用
    猜你喜欢
    • 2018-12-20
    • 2018-10-10
    • 2016-10-31
    • 2022-01-15
    • 2020-10-26
    • 2021-05-17
    • 1970-01-01
    • 2015-07-19
    • 2020-10-28
    相关资源
    最近更新 更多