Python Forum
F-score, Precision, and Recall values
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
F-score, Precision, and Recall values
#1
from tensorflow.keras import backend as K
.
.
.
def computeMetrics(true, pred): # considering sigmoid activation, threshold = 0.5
pred = K.cast(K.greater(pred, 0.5), K.floatx())

gP = K.cast( K.sum(true), K.floatx()) + K.epsilon()
cP = K.sum(true * pred) + K.epsilon()
pP = K.sum(pred) + K.epsilon()

precision = cP / pP
recall = cP / gP
f1 = (2 * precision * recall) / (precision + recall)

return f1, precision, recall

metrics =computeMetrics(y_test, y_pred)

print('metrics -----> ',metrics)


output:
metrics -----> (<tf.Tensor 'truediv_2:0' shape=() dtype=float32>, <tf.Tensor 'truediv:0' shape=() dtype=float32>, <tf.Tensor 'truediv_1:0' shape=() dtype=float32>)



Anyone can help to get the values from the metrics ?
Reply


Messages In This Thread
F-score, Precision, and Recall values - by Hani - May-07-2020, 08:58 PM
RE: F-score, Precision, and Recall values - by Hani - May-09-2020, 12:01 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  precision & recall gracenz 1 1,042 Sep-21-2022, 02:14 AM
Last Post: jefsummers
  Time class with picosecond precision marcocod 5 3,756 Jul-03-2020, 12:12 AM
Last Post: Larz60+
  F-score and Recall values Greater Than 1 Hani 5 2,589 May-13-2020, 01:47 AM
Last Post: Hani
  Difference between R^2 and .score donnertrud 1 7,026 Jan-08-2020, 05:14 PM
Last Post: jefsummers
  problem to add precision, recall and f1-score edys 7 4,207 May-28-2019, 04:48 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020