daily pastebin goal
51%
SHARE
TWEET

Untitled

a guest Feb 11th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def auc_roc(y_true, y_pred):
  2.    auc, up_opt = tf.metrics.auc(y_true, y_pred)
  3.    K.get_session().run(tf.local_variables_initializer())
  4.    with tf.control_dependencies([up_opt]):
  5.        auc = tf.identity(auc)
  6.    return auc
  7.    
  8. from sklearn.metrics import roc_auc_score
  9. from keras.callbacks import Callback
  10.  
  11. class IntervalEvaluation(Callback):
  12.     def __init__(self, validation_data=(), interval=10):
  13.         super(Callback, self).__init__()
  14.  
  15.         self.interval = interval
  16.         self.X_val, self.y_val = validation_data
  17.  
  18.     def on_epoch_end(self, epoch, logs={}):
  19.         if epoch % self.interval == 0:
  20.             y_pred = self.model.predict_proba(self.X_val, verbose=0)
  21.             score = roc_auc_score(self.y_val, y_pred)
  22.             print("interval evaluation - epoch: {:d} - score: {:.6f}".format(epoch, score))
  23.    
  24. ival = IntervalEvaluation(validation_data=(x_test2, y_test2), interval=1)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top