xgboost自定义损失函数&评估函数

https://blog.csdn.net/zwqjoy/article/details/121289448

 

def __fix_mse_obj__(self,labels, preds):  ##都是label在前,pred在后,经测试,lgb不能颠倒,xgb颠倒无影响,但是就统一用一种顺序
error = labels * 0.2
error = error.clip(min=2) ##允许偏差门槛
residual = (labels - preds).astype("float")
res = abs(residual) - error
grad = np.where(res < 0, -1 * residual, -1 * residual)
hess = np.where(res < 0, 20.0, 1.0)
return grad, hess

 

 

 天坑:hess处写2.0和2,又显著的差距

posted @ 2022-07-05 14:15  笨笨和呆呆  阅读(641)  评论(0)    收藏  举报