我需要以下 MATLAB 代码的 python 等效代码:
[f,xi] = ksdensity(data,'Support','positive','Function','cdf');
我找到下面的 python 代码,但我不知道如何提供它的cdf
. 如果您能指导我,我将不胜感激。
from scipy import stats
kde = stats.gaussian_kde(data)
我需要以下 MATLAB 代码的 python 等效代码:
[f,xi] = ksdensity(data,'Support','positive','Function','cdf');
我找到下面的 python 代码,但我不知道如何提供它的cdf
. 如果您能指导我,我将不胜感激。
from scipy import stats
kde = stats.gaussian_kde(data)
试试这个, 链接。
def insert_size(insert_size_distribution):
"""Calculate cumulative distribution function from the raw insert size
distributin. Uses 1D kernel density estimation.
Args:
insert_size_distribution (list): list of insert sizes from aligned
read pairs
Returns:
1darray: a cumulative density function
"""
kde = stats.gaussian_kde(
insert_size_distribution,
bw_method=0.2 / np.std(insert_size_distribution, ddof=1))
x_grid = np.linspace(
min(insert_size_distribution),
max(insert_size_distribution), 1000)
kde = kde.evaluate(x_grid)
cdf = np.cumsum(kde)
cdf = cdf / cdf[-1]
return cdf
以下代码适用于我:
import scipy
kde = scipy.stats.gaussian_kde(data)
my_cdf = scipy.stats.norm.cdf(kde)