What's the threshold value of binary_accuracy
in keras Metrices is used to predicted one sample as positive and negative cases? is that threshold value 0.5? how to adjust it? I want to set the threshold value 0.80, if the predicted value is 0.79, then it is considered a negative sample,otherwise,if the predicted value is 0.81, then it is considered a positive sample.
binary_accuracy
don't have threshold param but you can easily define one yourself.
import keras
from keras import backend as K
def threshold_binary_accuracy(y_true, y_pred):
threshold = 0.80
if K.backend() == 'tensorflow':
return K.mean(K.equal(y_true, K.tf.cast(K.lesser(y_pred,threshold), y_true.dtype)))
else:
return K.mean(K.equal(y_true, K.lesser(y_pred,threshold)))
a_pred = K.variable([.1, .2, .6, .79, .8, .9])
a_true = K.variable([0., 0., 0., 0., 1., 1.])
print K.eval(keras.metrics.binary_accuracy(a_true, a_pred))
print K.eval(threshold_binary_accuracy(a_true, a_pred))
Now you can use it as metrics=[threshold_binary_accuracy]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With