-1
我知道以前有关于该主题的问题,但我找不到我的问题的具体情况。我试图在直方图上绘制泊松分布。我试着在SciPy的使用泊松功能从统计模块的第一件事:叠加泊松分布到直方图
import numpy
from scipy.stats import poisson
mu = mean(data)
n, bins, patches = pyplot.hist(data, 20, normed = 1)
pyplot.plot(bins, poisson.pmf(bins, mu), 'r-')
pyplot.show()
然而,由于如图所示(图中蓝色我的数据的柱状图),我得到的红色情节有三个山峰怪异。
因此我试着写我自己的泊松分布函数:
def poisson(mu, x):
from scipy.misc import factorial
return numpy.exp(-mu) * mu**x * factorial(x)**-1
y = poisson(mu, bins)
但是,当我尝试打印它,我得到楠的数组。难道我做错了什么?或者是垃圾箱里的数字太大?
print y
[ nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan]
但是打印从stats.poisson结果时,我得到:
[3.25452236e-06 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 3.63110218e-04 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 5.24385396e-03 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 1.06061293e-02
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
3.23183010e-03]
嗨,好吧,我想通了,对我自己的阶乘函数我不得不做出的垃圾箱整数,我不知道为什么它没有对泊松发生功能在scipy模块中。有点愚蠢的我。谢谢! – user3412058