network.py 文件源码

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

项目:AMBR 作者: Algomorph 项目源码 文件源码
def compute_precision_and_recall(confusion_matrix):
        correct_predictions = np.diagonal(confusion_matrix)
        samples_per_class = np.sum(confusion_matrix, axis=0)
        false_positives = np.sum(confusion_matrix, axis=1) - correct_predictions
        false_negatives = samples_per_class - correct_predictions

        prectmp = correct_predictions / (correct_predictions + false_positives)
        prectmp[np.where(correct_predictions == 0)[0]] = 0
        prectmp[np.where(samples_per_class == 0)[0]] = float('nan')
        precision = np.nanmean(prectmp)

        rectmp = correct_predictions / (correct_predictions + false_negatives)
        rectmp[np.where(correct_predictions == 0)[0]] = 0
        rectmp[np.where(samples_per_class == 0)[0]] = float('nan')
        recall = np.nanmean(rectmp)
        return precision, recall
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号