How to calculate F1 Macro in Keras?

后端 未结 6 1708
逝去的感伤
逝去的感伤 2020-11-28 23:13

i\'ve tried to use the codes given from Keras before they\'re removed. Here\'s the code :

def precision(y_true, y_pred):
    true_positives = K.sum(K.round(K         


        
6条回答
  •  广开言路
    2020-11-28 23:15

    Using a Keras metric function is not the right way to calculate F1 or AUC or something like that.

    The reason for this is that the metric function is called at each batch step at validation. That way the Keras system calculates an average on the batch results. And that is not the right F1 score.

    Thats the reason why F1 score got removed from the metric functions in keras. See here:

    • https://github.com/keras-team/keras/commit/a56b1a55182acf061b1eb2e2c86b48193a0e88f7
    • https://github.com/keras-team/keras/issues/5794

    The right way to do this is to use a custom callback function in a way like this:

    • https://github.com/PhilipMay/mltb#module-keras
    • https://medium.com/@thongonary/how-to-compute-f1-score-for-each-epoch-in-keras-a1acd17715a2

提交回复
热议问题