Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. def GAP(pred, conf, true):
  2. x = pd.DataFrame({'pred': pred, 'conf': conf, 'true': true})
  3. x.sort_values('conf', ascending=False, inplace=True, na_position='last')
  4. x['correct'] = (x.true == x.pred).astype(int)
  5. x['prec_k'] = x.correct.cumsum() / (np.arange(len(x)) + 1)
  6. x['term'] = x.prec_k * x.correct
  7. gap = x.term.sum() / x.true.count()
  8.  
  9. return gap
  10.  
  11. model.compile(loss='my_loss',metrics=[GAP])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement