我有1000个大数字,随机分布在37231到56661之间。
我正在尝试使用stats.gaussian_kde
,但有些东西不起作用。
(也许是因为我对统计知识的贫乏?)。
代码如下:
from scipy import stats.gaussian_kde
import matplotlib.pyplot as plt
# 'data' is a 1D array that contains the initial numbers 37231 to 56661
xmin = min(data)
xmax = max(data)
# get evenly distributed numbers for X axis.
x = linspace(xmin, xmax, 1000) # get 1000 points on x axis
nPoints = len(x)
# get actual kernel density.
density = gaussian_kde(data)
y = density(x)
# print the output data
for i in range(nPoints):
print "%s %s" % (x[i], y[i])
plt.plot(x, density(x))
plt.show()
在打印输出中,我在列1中得到x值,在列2中得到0。 这个图显示了一条平线。
我就是找不到解决办法。 我试了很多X-es,结果都一样。
怎么了?我做错什么了? 大量的数据可能是原因吗?
我做了一个函数来做这个。你可以改变带宽作为函数的参数。也就是说,较小的数字=更尖,较大的数字=更平滑。默认值为0.3。
它在
IPython notebook --pylab=inline
中工作存储箱的数量经过优化和编码,因此会因数据中变量的数量而有所不同。
我认为发生的情况是,您的数据数组是由整数组成的,这会导致以下问题:
但如果我们使用浮点数:
相关问题 更多 >
编程相关推荐