I tried implementing weighted binary cross-entropy with Keras, but I'm not sure if the code is correct. The learning outcome is a bit confusing. After several eras, I get an accuracy of ~ 0.15. I think this is much less (even for a random guess).
In the general case, about 11% of units and 89% of zeros, therefore, the weights w_zero = 0.89 and w_one = 0.11.
My code is:
def create_weighted_binary_crossentropy(zero_weight, one_weight):
def weighted_binary_crossentropy(y_true, y_pred):
b_ce = K.binary_crossentropy(y_true, y_pred)
weight_vector = y_true * one_weight + (1. - y_true) * zero_weight
weighted_b_ce = weight_vector * b_ce
return K.mean(weighted_b_ce)
return weighted_binary_crossentropy
Can someone see what is wrong?
thank
source
share