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]
评论列表
文章目录