Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. # Accuracy
  2. with tf.name_scope("accuracy"):
  3. correct_predictions = tf.equal(self.predictions, tf.argmax(self.input_y, 1))
  4. self.accuracy = tf.reduce_mean(tf.cast(correct_predictions, "float"), name="accuracy")
  5.  
  6. confusion_matrix[16][7]+=1
  7.  
  8. y_ = tf.placeholder(tf.float32, shape=[None, 2])
  9. y = last_layer(d/2,2,h_fc1_drop)
  10. confusion_matrix_tf = tf.confusion_matrix(tf.argmax(y, 1), tf.argmax(y_, 1))
  11.  
  12. cm = confusion_matrix_tf.eval(feed_dict={x: X_train, y_: y_train, keep_prob: 1.0})
  13.  
  14. def beautyCM(cm, ind=['True pos', 'True neg'], cols=['Pred pos', 'Pred neg']):
  15. return pd.DataFrame(cm, index=ind, columns=cols)
  16.  
  17. def precision(cm):
  18. # prec = TP / (TP + FP)
  19. try:
  20. return round(float(cm.loc['True pos', 'Pred pos']) /
  21. (cm.loc['True pos', 'Pred pos'] + cm.loc['True neg', 'Pred pos']), 4)
  22. except ZeroDivisionError:
  23. return 1.0
  24.  
  25.  
  26. def recall(cm):
  27. # prec = TP / (TP + FN)
  28. try:
  29. return round(float(cm.loc['True pos', 'Pred pos']) /
  30. (cm.loc['True pos', 'Pred pos'] + cm.loc['True pos', 'Pred neg']), 4)
  31. except ZeroDivisionError:
  32. return 1.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement