def plotROC(self):
for classifier in self.structures:
x, y = [], []
for threshold in np.arange(self.minScore, self.maxScore, 0.1):
tp, tn, fp, fn = 0, 0, 0, 0
for realS in self.structures:
for score in self.scores[(classifier, realS)]:
if score >= threshold: # Positive
if classifier == realS: # True
tp += 1
else: # False
fp += 1
else: # Negative
if classifier != realS: # True
tn += 1
else: # False
fn += 1
tpr = tp / (tp + fn)
fpr = fp / (tn + fp)
x.append(fpr)
y.append(tpr)
print("----- Receiver Operating Characteristic Curve -----")
print("Classifier:", classifier)
x.sort()
y.sort()
auc = np.trapz(y, x) # Area Under Curve
print("AUC:", auc)
pyplot.title("Classifier " + classifier)
pyplot.xlabel('False Positive Rate')
pyplot.ylabel('True Positive Rate')
pyplot.plot([0, 1], [0, 1])
pyplot.plot(x, y)
pyplot.show()
评论列表
文章目录