Created
April 6, 2016 08:02
-
-
Save eqs/c004bc57f14db825c8970b44de4a0dab to your computer and use it in GitHub Desktop.
ROC test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Created on 04/06/16 14:08:31 | |
ROC曲線を「はじめてのパターン認識」(P.34) に基づいて描く | |
@author: Satoshi MURASHIGE | |
""" | |
import sys | |
import numpy as np | |
import matplotlib.pyplot as plt | |
# 識別器が出した得点 | |
data_scores = np.array([0.9, | |
0.8, | |
0.7, | |
0.55, | |
0.45, | |
0.4, | |
0.34, | |
0.3, | |
0.2, | |
0.1]) | |
# 事実 | |
data_labels = np.array([1, | |
1, | |
0, | |
1, | |
1, | |
0, | |
0, | |
1, | |
0, | |
0]) | |
# 閾値を変えながら識別器に予測させる | |
TP = np.zeros(data_scores.shape[0] + 1) | |
FP = np.zeros(data_scores.shape[0] + 1) | |
for k, th in enumerate(np.concatenate(([100], data_scores))): | |
# 識別器の予測 | |
predict = np.float32(data_scores >= th) | |
TP[k] = np.count_nonzero(data_labels[data_labels == predict]) / np.count_nonzero(data_labels) | |
FP[k] = np.count_nonzero(1 - data_labels[data_labels != predict]) / np.count_nonzero(1 - data_labels) | |
plt.xlim(0, 1) | |
plt.ylim(0, 1) | |
plt.plot(FP, TP, linewidth=5) | |
plt.plot(FP, TP, 'ro', markersize=10) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment