我有一个保存在1D列表中的1D数据集。获得概率密度函数的最佳方法是什么?我尝试了使用scipy gaussian_kde的常用方法。
array = np.array(values)
kde = gaussian_kde(array)
x = np.linspace(0, 50, 500)
plt.plot(x, kde(x), label="", color="blue")
plt.legend(loc='best')
plt.show()

产生的图不是预期的概率密度函数,因为对于每个x,概率密度函数的值应该在0到1之间。
谢谢
发布于 2019-05-16 17:27:07
使用以下代码。
import os
import matplotlib.pyplot as plt
import sys
import math
import numpy as np
import scipy.stats as st
from scipy.stats._continuous_distns import _distn_names
from scipy.optimize import curve_fit
def get_pdf(latency_list):
np_array = np.array(latency_list) # convert the list into a numpy array
ag = st.gaussian_kde(np_array) # calculate the kernel density function for the latency values
# list of equidistant values in the range of the latency values
x = np.linspace(min(latency_list), max(latency_list), (max(latency_list) - min(latency_list)) * 10)
y = ag(x) # evaluate the latency values for each x value
return x, yhttps://stackoverflow.com/questions/51536068
复制相似问题