python - 将直方图与泊松分布和高斯曲线进行比较

标签 python histogram poisson

我得到了 100 个实验值:

N = np.array([ 6080, 5604, 5972, 5566, 5683, 5619, 5582, 5912, 5614,5837, 5961, 5972, 5807, 5829, 5881, 5757, 5725, 5809, 5626, 5995, 5793, 5608, 5880, 5982, 5748, 6071, 6181, 6034, 6117, 5903, 6190, 5735, 6109, 6126, 6012, 5948, 6139, 6103, 6108, 6031, 6200, 6091, 6199, 6165, 6591, 5803, 6093, 5921, 6194, 5799, 6020, 6156, 6129, 6344, 6243, 6122, 5926, 5904, 5579, 5881, 6157, 5925, 5835, 5778, 6125, 5737, 5703, 5809, 6109, 5978, 5881, 6250, 6143, 5658, 5815, 5633, 5780, 5620, 6180, 5770, 6058, 5688, 5792, 6170, 5915, 6147, 5727, 6300, 6049, 6263, 6168, 6156, 6071, 6196, 6078, 5848, 5847, 6248, 6243, 6084])

现在我想将其与泊松分布和高斯分布进行比较。 我想将曲线放在直方图的顶部:

enter image description here]

但它不起作用。 例如使用泊松分布:我想拟合直方图上的泊松分布

b = np.sqrt(len(N)) 
w = np.ones_like(N)/float(len(N))

entries, bin_edges, patches = plt.hist(N, bins=b, weights=w)


def poisson(x, lamb):
    return (lamb**x/factorial(x)) * np.exp(-lamb) 

parameters, cov_matrx = curve_fit(poisson, bin_middles, entries)

但是当我绘制它时,它甚至还差得远

plt.plot(x_plot, poisson(x_plot, *parameters), 'r-', lw=2)

Where is Poisson?

你会如何解决这样的问题?我认为是因为我的值(value)观太高了。泊松区以 k = 0, 1, 2, .... 运行 我的就像 k' = 6000, 6200, ...

最佳答案

在您的图中有一条红线...它是泊松曲线。你用的是什么 lambda ?它很可能太小,你只会得到零。 无论如何,我建议您使用:poisson来自 scipy 的函数

def poisson(x, lamb):
    from scipy.stats import poisson as _poisson    
    return _poisson.pmf(x,lamb)

parameters, cov_matrx = curve_fit(poisson, bin_middles, entries, p0=6000)

您还应该将 normed=True 添加到您的第一个直方图

entries, bin_edges, patches = plt.hist(N, bins=b, weights=w, normed=True)

关于python - 将直方图与泊松分布和高斯曲线进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37463916/

相关文章:

python - GTK 和 PYGTK 的区别

javascript - D3 : incorporate two datasets in bin - histogram layout

elasticsearch - 是否可以在 Kibana 中使用 Histogram Facet 或其 curl 响应

c - 并行 (CUDA) 二维泊松求解器

r - 泊松回归线

python - Bokeh 图未在 nbviewer 中显示

python - 读取文本文件并将文件从其中移动到目录

python - cURL 不能通过 Python 3 中的子进程工作

python-2.7 - 带有 pyplot 的直方图中的垂直线

r - R 中泊松随机变量生成的改进逆变换方法