Last active
September 26, 2018 18:14
-
-
Save groverpr/bb937d1db98c2bfb2e7eca1765e64bdf to your computer and use it in GitHub Desktop.
How to write custom objective and custom eval metric in lightgbm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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