BinaryPerfIndicators.py 文件源码

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

项目:SecuML 作者: ANSSI-FR 项目源码 文件源码
def addProbabilistFold(self, fold_id, true_labels, predicted_proba, threshold = None):
        if threshold is None:
            for threshold in self.thresholds:
                self.addProbabilistFold(fold_id, true_labels, predicted_proba, threshold = threshold)
        else:
            predicted_labels = np.array(predicted_proba) > threshold / 100
            precision, recall, f_score, _ = precision_recall_fscore_support(true_labels, predicted_labels,
                                                                            average = 'binary')
            if len(predicted_labels) == 0:
                fp = 0
                tn = 0
            else:
                conf_matrix = confusion_matrix(true_labels, predicted_labels, [True, False])
                fp = conf_matrix[1][0]
                tn = conf_matrix[1][1]
            fp_tn = fp + tn
            if fp_tn == 0:
                false_alarm_rate = 0
            else:
                false_alarm_rate = fp / (fp + tn)
            self.fold_perf[threshold][fold_id, :] = [precision, recall, false_alarm_rate, f_score]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号