keras recall

Posted papio

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了keras recall相关的知识,希望对你有一定的参考价值。

# 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的主要内容,如果未能解决你的问题,请参考以下文章

keras recall

Tensorflow 中每个班级的 F1 分数指标

绘制阈值(precision_recall 曲线)matplotlib/sklearn.metrics

如何在 Keras 中计算精度和召回率

返回状态Keras-多变量输出

Precision、Recall 和 F1 可以是相同的值吗?