码迷,mamicode.com
首页 > 其他好文 > 详细

keras recall

时间:2019-05-15 15:51:25      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:clip   on()   dict   ssi   keras   ilo   span   round   psi   

# accuracy, fmeasure, precision,recall
def mcor(y_true, y_pred):
    y_pred_pos = K.round(K.clip(y_pred, 0, 1))
    y_pred_neg = 1-y_pred_pos

    y_pos = K.round(K.clip(y_true, 0, 1))
    y_neg = 1-y_pos

    tp = K.sum(y_pos*y_pred_pos)
    tn = K.sum(y_neg*y_pred_neg)

    fp = K.sum(y_neg*y_pred_pos)
    fn = K.sum(y_pos*y_pred_neg)

    numerator = (tp*tn - fp*fn)
    denominator = K.sqrt((tp+fp)*(tp+fn)*(tn+fp)*(tn+fn))

    return numerator/(denominator+K.epsilon())

def precision(y_true, y_pred):
    true_positives = K.sum(K.round(K.clip(y_true*y_pred, 0, 1)))
    predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1)))
    precision = true_positives / (predicted_positives + K.epsilon())
    return precision


def recall(y_true, y_pred):
    true_positives = K.sum(K.round(K.clip(y_true*y_pred, 0, 1)))
    possible_positives = K.sum(K.round(K.clip(y_true, 0, 1)))
    recall = true_positives/(possible_positives+K.epsilon())
    return recall

def f1(y_true, y_pred):
    def recall(y_true, y_pred):
        true_positives = K.sum(K.round(K.clip(y_true*y_pred, 0, 1)))
        possible_positives = K.sum(K.round(K.clip(y_true, 0, 1)))
        recall = true_positives/(possible_positives+K.epsilon())
        return recall

    def precision(y_true, y_pred):
        true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
        predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1)))
        precision = true_positives / (predicted_positives + K.epsilon())
        return precision

    precision = precision(y_true, y_pred)
    recall = recall(y_true, y_pred)
    return 2*((precision*recall)/(precision+recall+K.epsilon()))

 

keras recall

标签:clip   on()   dict   ssi   keras   ilo   span   round   psi   

原文地址:https://www.cnblogs.com/papio/p/10869652.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!