In [14]:
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as stats

sigma = 2
mu0   = 0
mu1   = 3
tauset = np.linspace(-5,5,1000)
PF = np.zeros(1000)
PD = np.zeros(1000)

for i in range(1000):
  tau = tauset[i]
  PF[i] = 1 - stats.norm.cdf((tau-mu0)/sigma)
  PD[i] = 1 - stats.norm.cdf((tau-mu1)/sigma)

tau = (mu1-mu0)/2
PFo = 1 - stats.norm.cdf((tau-mu0)/sigma)
PDo = 1 - stats.norm.cdf((tau-mu1)/sigma)

plt.plot(PF, PD, linewidth=4)
plt.plot(PFo, PDo, 'ro', markersize=10)
Out[14]:
[<matplotlib.lines.Line2D at 0x7f95e7ad20f0>]
In [16]:
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as stats
scores = np.loadtxt('ch9_ROC_example_data.txt')
labels = np.append(np.ones(50), np.zeros(50))
tau = np.linspace(0,1,1000)
PF = np.zeros(1000)
PD = np.zeros(1000)
for i in range(1000):
  idx = scores<= tau[i]
  predict = np.zeros(100)
  predict[idx] = 1
  true_positive  = 0
  true_negative  = 0
  false_positive = 0
  false_negative = 0
  for j in range(100):
    if (predict[j]==1) and (labels[j]==1): true_positive  += 1
    if (predict[j]==1) and (labels[j]==0): false_positive += 1
    if (predict[j]==0) and (labels[j]==1): false_negative += 1   
    if (predict[j]==0) and (labels[j]==0): true_negative  += 1
  PF[i] = false_positive/50
  PD[i] = true_positive/50
plt.plot(PF, PD, linewidth=4)
Out[16]:
[<matplotlib.lines.Line2D at 0x7f95e7986710>]
In [ ]:
%%shell
jupyter nbconvert --to html /content/ECE595_lecture09.ipynb