【发布时间】:2018-05-19 00:30:15
【问题描述】:
我正在处理一些时间序列数据,并尝试使用伽马分布拟合数据。但问题是拟合的pdf的幅度远低于直方图的幅度。这是我的代码和情节。剧情有什么问题?
# the data
data = contents[0][1:]
# normalized histogram
weights = np.ones_like(data)/len(data)
plt.hist(data, bins = 20, color = 'w', edgecolor = 'black', alpha = 0.5, weights = weights)
# fit with gamma distribution and plot the pdf
dist = getattr(scipy.stats, 'gamma')
param = dist.fit(data)
x = np.linspace(min(data), max(data), 100)
pdf_fit = dist.pdf(x, *param[:-2], loc = param[-2], scale = param[-1])
plt.plot(x, pdf_fit/sum(pdf_fit), label = 'Gamma')
plt.legend(loc = 'upper right')
plt.show()
【问题讨论】:
标签: python pdf scipy histogram data-fitting