Skip to content

Instantly share code, notes, and snippets.

@groverpr
Last active September 26, 2018 18:14
Show Gist options
  • Select an option

  • Save groverpr/bb937d1db98c2bfb2e7eca1765e64bdf to your computer and use it in GitHub Desktop.

Select an option

Save groverpr/bb937d1db98c2bfb2e7eca1765e64bdf to your computer and use it in GitHub Desktop.
How to write custom objective and custom eval metric in 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment