May-07-2020, 08:58 PM
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 ?
.
.
.
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 ?