在Python中将等方差信号检测模型拟合为ROC数据

时间:2018-06-01 08:54:53

标签: python numpy matplotlib scipy roc

我有一个问题,感觉有点像是在这里得到解决但我似乎无法在其他任何地方找到任何帮助,所以在这里。

我想将等方差信号检测模型拟合到某些ROC数据,这样我就可以在与我的数据相同的图上绘制模型曲线。 Here is a paper that I was following for example,其中有一个带有步骤的excel文件的图像,以及一些公式。但是,尽管遵循了这些步骤,我仍然无法复制估算它的值,并且可以使用更有知识的人的一些帮助。这是我的代码以及步骤和输出图的注释,看起来不正确:

import numpy as np
from scipy import stats
import matplotlib.pyplot as plt


def convert_to_proportions(x, corrected=True):

    if corrected == True:
        converted = [((j + (i + 1) / 6) / (x[-1] + 1)) for i, j in enumerate(x[:-1])]
        converted.append(x[-1] / x[-1])
        return converted
    else:
        return [(i / x[-1]) for i in x]


def get_d_prime(H, F):

    d_prime = stats.norm.ppf(H) - stats.norm.ppf(F)

    return d_prime


def get_c(H, F):
    c = -(stats.norm.ppf(H) + stats.norm.ppf(F)) / 2
    return c


### Input the signal and noise values
## "sure signal", "likely signal", "guess signal", ... ... "sure noise"
signal = [1230, 496, 358, 272, 215, 165]
noise = [111, 216, 349, 540, 625, 895]

# cumulate them
csignal, cnoise = np.cumsum(signal), np.cumsum(noise)

# convert them to proportions and correct so that all but the last elements will never equal 1
propsignal = convert_to_proportions(csignal)
propnoise = convert_to_proportions(cnoise)

# calculate d' for all, except for the last element which is always 1.
d_primes = [get_d_prime(i[0], i[1]) for i in zip(propsignal[0:-1], propnoise[0:-1])]

# calculate c in the same way
cs = [get_c(i[0], i[1]) for i in zip(propsignal[0:-1], propnoise[0:-1])]

#estimate the noise and signal curves. 
#*** This is where my numbers disagree with those in the paper.
estimated_noise = [stats.norm.cdf(-c) for c in cs]
estimated_signal = [stats.norm.cdf(np.mean(d_primes) - c) for c in cs]

# plot the scattered data and estimated model
plt.close('all')
fig, ax = plt.subplots()

ax.plot([0, 1], [0, 1], c='black', ls='dashed')
ax.scatter(propnoise[0:-1], propsignal[0:-1], label='data')
ax.plot(estimated_noise, estimated_signal, c='black', label='model')

ax.set_xlabel('FA')
ax.set_ylabel('hit')

ax.legend()
plt.show()

enter image description here

正如你所看到的,看看我的情节,模型根本不适合数据并且错误,因为它应该如链接纸中的图5(a)所示。我不确定出现了什么问题,或者作者如何得出他们所做的c值,因为我使用相同的公式计算c然后分别估算H和F率,但我只是得出不同的值。

0 个答案:

没有答案