machine learning - Keras: weighted binary crossentropy ...
stackoverflow.com › questions › 46009619Sep 02, 2017 · one_weight = (1-num_of_ones)/(num_of_ones + num_of_zeros) zero_weight = (1-num_of_zeros)/(num_of_ones + num_of_zeros) def weighted_binary_crossentropy(zero_weight, one_weight): def weighted_binary_crossentropy(y_true, y_pred): b_ce = K.binary_crossentropy(y_true, y_pred) # weighted calc 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
Cross entropy - Wikipedia
https://en.wikipedia.org/wiki/Cross_entropyDefinition. The cross-entropy of the distribution relative to a distribution over a given set is defined as follows: (,) = [],where [] is the expected value operator with respect to the distribution .. The definition may be formulated using the Kullback–Leibler divergence (‖), divergence of from (also known as the relative entropy of with respect to ).