PConsC2.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:Master-Thesis 作者: AntoinePassemiers 项目源码 文件源码
def get_metrics(predictions, targets):
    assert(np.logical_or(predictions == 1, predictions == 0).all())
    assert(np.logical_or(targets == 1, targets == 0).all())
    TP  = np.logical_and(predictions == 1, targets == 1).sum()
    FP  = np.logical_and(predictions == 1, targets == 0).sum()
    FN  = np.logical_and(predictions == 0, targets == 1).sum()
    TN  = np.logical_and(predictions == 0, targets == 0).sum()
    N   = TP + FP + FN + TN

    PPV = float(TP) / float(TP + FP) if TP != 0.0 else 0.0
    FPV = float(TN) / float(TN + FN) if TN != 0.0 else 0.0
    ACC = float(TP + TN) / float(N)
    TPR = float(TP) / float(TP + FN) if TP != 0.0 else 0.0
    FPR = float(FP) / float(FP + TN) if FP != 0.0 else 0.0
    tp, tn, fp, fn = float(TP) / N, float(TN) / N, float(FP) / N, float(FN) / N
    MCC = float(tp*tn - fp*fn) / (np.sqrt(tp+fp)*np.sqrt(tp+fn)*np.sqrt(tn+fp)*np.sqrt(tn+fn))
    F1 = 2 * TP / float(2 * TP + FP + FN)
    metrics = {
        "TP": TP, "FP": FP, "FN": FN, "TN": TN, "N": N,
        "PPV": PPV, "FPV": FPV, "MCC": MCC, "ACC": ACC,
        "F1": F1
    }
    return metrics
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号