问题描述
我已经上网了,还没有找到答案或方法来说明以下内容
I've looked online and have yet to find an answer or way to figure the following
我正在将一些MATLAB代码转换为Python,在MATLAB中,我希望通过以下功能找到内核密度估算值:
I'm translating some MATLAB code to Python where in MATLAB im looking to find the kernel density estimation with the function:
[p,x] = ksdensity(data)
其中p是分布中x点的概率.
where p is the probability at point x in the distribution.
Scipy具有功能,但仅返回p.
Scipy has a function but only returns p.
有没有一种方法可以找到x值处的概率?
Is there a way to find the probability at values of x?
谢谢!
推荐答案
这种形式的ksdensity
调用会自动生成任意的x
. scipy.stats.gaussian_kde()
返回一个可调用函数,可以使用您选择的任何x
对其进行求值.等价的x
将是np.linspace(data.min(), data.max(), 100)
.
That form of the ksdensity
call automatically generates an arbitrary x
. scipy.stats.gaussian_kde()
returns a callable function that can be evaluated with any x
of your choosing. The equivalent x
would be np.linspace(data.min(), data.max(), 100)
.
import numpy as np
from scipy import stats
data = ...
kde = stats.gaussian_kde(data)
x = np.linspace(data.min(), data.max(), 100)
p = kde(x)
这篇关于Python中的MATLAB ksdensity等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!