I have a machine learning problem that I believe the negative binomial loss function would fit well, but the light gbm package doesn't have it as a standard, I'm trying to implement it, but I'm don't know how to get Gradient and Hessian, does anyone know how I can do this? I managed to get to the loss function, but I can't get to the gradient and hessian.
import math
def custom_asymmetric_valid(y_pred,y_true):
y_true = y_true.get_label()
p = 0.5
n = y_pred
loss = math.gamma(n) + math.gamma(y_true + 1) - math.gamma(n + y_true) - n * math.log(p) - y_true * math.log(1 - p)
return "custom_asymmetric_eval", np.mean(loss), False
Now how to get the Gradient and Hessian?
def custom_asymmetric_train(y_pred,y_true):
residual = (y_true.get_label() - y_pred).astype("float")
grad = ?
hess = ?
return grad, hess
Anyone could help?