Guest User

Untitled

a guest
Oct 23rd, 2019
87
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def focal_loss_lgb(y_pred, dtrain, alpha, gamma):
  2. a,g = alpha, gamma
  3. y_true = dtrain.label
  4. def fl(x,t):
  5. p = 1/(1+np.exp(-x))
  6. return -( a*t + (1-a)*(1-t) ) * (( 1 - ( t*p + (1-t)*(1-p)) )**g) * ( t*np.log(p)+(1-t)*np.log(1-p) )
  7. partial_fl = lambda x: fl(x, y_true)
  8. grad = derivative(partial_fl, y_pred, n=1, dx=1e-6)
  9. hess = derivative(partial_fl, y_pred, n=2, dx=1e-6)
  10. return grad, hess
RAW Paste Data