对二维数据使用scipy.stats.gaussian_kde [英] Using scipy.stats.gaussian_kde with 2 dimensional data
问题描述
我正在尝试使用 scipy.stats.gaussian_kde
类,以平滑一些通过纬度和经度信息收集的离散数据,因此最终显示出的轮廓图与等高线图类似,其中高密度是峰值,而低密度是谷.
I'm trying to use the scipy.stats.gaussian_kde
class to smooth out some discrete data collected with latitude and longitude information, so it shows up as somewhat similar to a contour map in the end, where the high densities are the peak and low densities are the valley.
我很难将二维数据集放入gaussian_kde
类.我一直在努力弄清楚它如何处理一维数据,因此我认为二维将遵循以下原则:
I'm having a hard time putting a two-dimensional dataset into the gaussian_kde
class. I've played around to figure out how it works with 1 dimensional data, so I thought 2 dimensional would be something along the lines of:
from scipy import stats
from numpy import array
data = array([[1.1, 1.1],
[1.2, 1.2],
[1.3, 1.3]])
kde = stats.gaussian_kde(data)
kde.evaluate([1,2,3],[1,2,3])
,我在[1.1, 1.1], [1.2, 1.2], [1.3, 1.3]
上有3分.并且我想使用x和y轴上的1的宽度使用1到3进行内核密度估计.
which is saying that I have 3 points at [1.1, 1.1], [1.2, 1.2], [1.3, 1.3]
. and I want to have the kernel density estimation using from 1 to 3 using width of 1 on x and y axis.
创建gaussian_kde时,它会不断显示此错误:
When creating the gaussian_kde, it keeps giving me this error:
raise LinAlgError("singular matrix")
numpy.linalg.linalg.LinAlgError: singular matrix
查看gaussian_kde
的源代码,我意识到我在思考数据集含义的方式与维数的计算方式完全不同,但是我找不到任何示例代码来显示多维数据的方式与模块一起使用.有人可以帮我一些将gaussian_kde
用于多维数据的示例方法吗?
Looking into the source code of gaussian_kde
, I realize that the way I'm thinking about what dataset means is completely different from how the dimensionality is calculate, but I could not find any sample code showing how multi-dimension data works with the module. Could someone help me with some sample ways to use gaussian_kde
with multi-dimensional data?
推荐答案
显然,斧头需要固定.
您还可以使用
scatter(rvs[:,0],rvs[:,1])
这篇关于对二维数据使用scipy.stats.gaussian_kde的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!