【问题标题】:How to get probability density function using scipy gaussian_kde?如何使用 scipy gaussian_kde 获得概率密度函数?
【发布时间】:2019-05-16 17:27:06
【问题描述】:

我有一个保存在一维列表中的一维数据集。获得概率密度函数的最佳方法是什么?我尝试了使用 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 之间。

谢谢

【问题讨论】:

    标签: python statistics


    【解决方案1】:

    使用以下代码。

    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, y
    

    【讨论】:

      猜你喜欢
      • 2020-08-07
      • 2015-07-31
      • 1970-01-01
      • 1970-01-01
      • 2010-11-12
      • 2012-11-21
      • 2014-07-01
      • 2016-06-01
      • 2019-04-19
      相关资源
      最近更新 更多