Gamma分布拟合误差

时间:2013-08-12 15:03:52

标签: scipy classification gamma-distribution

对于分类任务,我想将伽玛分布拟合到两对数据:类内和类之间的距离。这是为了确定理论上的错误接受率和错误拒绝率。

适合Scipy回归让我感到困惑。下面是数据图,其中圆表示类距离和类距离之间的x-es,实线是类内的拟合伽玛,虚线是类距离之间的拟合伽玛。 enter image description here

我所期望的是伽马曲线将在~10和~30左右达到峰值,而对于两者都不是0。有谁看到这里出了什么问题?

这是我的代码:

pos = [7.4237931034482765, 70.522068965517235, 9.1634482758620681, 22.594137931034485, 7.3003448275862075, 6.3841379310344841, 10.693448275862071, 7.5237931034482761, 7.4079310344827594, 7.2696551724137928, 8.5551724137931036, 17.647241379310344, 7.8475862068965521, 14.397586206896554, 32.278965517241382]
neg = [32.951724137931038, 234.65724137931034, 25.530000000000001, 33.236551724137932, 258.49965517241378, 33.881724137931037, 18.853448275862071, 33.703103448275861, 33.655172413793103, 33.536551724137929, 37.950344827586207, 34.32586206896552, 42.997241379310346, 100.71379310344828, 32.875172413793102, 30.59344827586207, 19.857241379310345, 35.232758620689658, 30.822758620689655, 34.92896551724138, 29.619310344827586, 29.236551724137932, 32.668620689655171, 30.943448275862071, 30.80344827586207, 88.638965517241374, 25.518620689655172, 38.350689655172417, 27.378275862068971, 37.138620689655177, 215.63379310344828, 344.93896551724134, 225.93413793103446, 103.66758620689654, 81.92896551724138, 59.159999999999997, 463.89379310344827, 63.86827586206897, 50.453103448275861, 236.4603448275862, 273.53137931034485, 236.26103448275862, 216.26758620689654, 170.3003448275862, 340.60034482758618]

alpha1, loc1, beta1=ss.gamma.fit(pos, floc=0)
alpha2, loc2, beta2=ss.gamma.fit(neg, floc=0)

plt.plot(pos,[0.06]*len(pos),'ko')
plt.plot(neg,[0.04]*len(neg),'kx')

x = range(200)
plt.plot(x,ss.gamma.pdf(x, alpha1, scale=beta1), '-k')
plt.plot(x,ss.gamma.pdf(x, alpha2, scale=beta2), ':k')
plt.xlim((0,200))

floc = 0的技巧我从这里得到:Why does the Gamma distribution in SciPy have three parameters?但它并不总是强迫loc1和loc2为0:/

1 个答案:

答案 0 :(得分:1)

(这是一个评论,但我想展示我得到的情节。)

制作情节时,您确定在floc=0方法中使用了fit吗?如果我把它遗漏(或者如果我犯了错误 - 就像我经常那样 - 使用loc=0而不是floc=0),我会得到一个看起来像你所包含的情节。

您使用的是scipy和numpy的哪个版本?

使用scipy 0.12.0和numpy 1.7.1,您的代码适合我。我添加了几个print语句,我得到了:

alpha1 = 1.86456504055  beta1 = 8.47415903767
alpha2 = 1.17943740138  beta2 = 86.51957394

以及情节:

enter image description here