如何绘制事件到达间隔时间的概率密度函数(PDF)? [英] how to plot Probability density Function (PDF) of inter-arrival time of events?

查看:195
本文介绍了如何绘制事件到达间隔时间的概率密度函数(PDF)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据值数组,如下所示:

I have an array of data values as follows :

0.000000000000000000e+00
3.617000000000000171e+01
1.426779999999999973e+02
2.526699999999999946e+01
4.483190000000000168e+02
7.413999999999999702e+00
1.132390000000000043e+02
8.797000000000000597e+00
1.362599999999999945e+01
2.080880900000000111e+04
5.580000000000000071e+00
3.947999999999999954e+00
2.615000000000000213e+00
2.458000000000000185e+00
8.204600000000000648e+01
1.641999999999999904e+00
5.108999999999999986e+00
2.388999999999999790e+00
2.105999999999999872e+00
5.783000000000000362e+00
4.309999999999999609e+00
3.685999999999999943e+00
6.339999999999999858e+00
2.198999999999999844e+00
3.568999999999999950e+00
2.883999999999999897e+00
7.307999999999999829e+00
2.515000000000000124e+00
3.810000000000000053e+00
2.829000000000000181e+00
2.593999999999999861e+00
3.963999999999999968e+00
7.258000000000000007e+00
3.543000000000000149e+00
2.874000000000000110e+00
................... and so on. 

我想绘制数据值的概率密度函数.我提到了(维基)

I want to plot Probability Density function of the data values. I referred (Wiki) and scipy.stats.gaussian_kde. but i am not getting that is correct or not. i am using python. simple data plot code is as follows :

from matplotlib import pyplot as plt
plt.plot(Data)

但是现在我想绘制PDF(概率密度函数).但是我没有在python中获取任何库来这样做.

But now i want to plot PDF (Probability Density Function). But i am not getting any library in python to do so.

推荐答案

您提供的数据集很小,无法进行可靠的内核密度估计.因此,我将通过使用另一个数据集来演示该过程(如果我正确理解了您要执行的操作)

The dataset you provide is very small to allow for a reliable kernel-density estimation. Therefore, I will demostrate the procedure (if I understood correctly what you are trying to do) by using another data set

import numpy as np
import scipy.stats

# generate data samples
data = scipy.stats.expon.rvs(loc=0, scale=1, size=1000, random_state=123)

然后只需调用即可获得内核密度估计

A kernel density estimation can then be obtained by simply calling

scipy.stats.gaussian_kde(data,bw_method=bw)

其中,bw是估计过程的(可选)参数.对于此数据集,并考虑bw的三个值,拟合如下所示

where bw is an (optional) parameter for the estimation procedure. For this data set, and considering three values for bw the fit is as shown below

# test values for the bw_method option ('None' is the default value)
bw_values =  [None, 0.1, 0.01]

# generate a list of kde estimators for each bw
kde = [scipy.stats.gaussian_kde(data,bw_method=bw) for bw in bw_values]


# plot (normalized) histogram of the data
import matplotlib.pyplot as plt 
plt.hist(data, 50, normed=1, facecolor='green', alpha=0.5);

# plot density estimates
t_range = np.linspace(-2,8,200)
for i, bw in enumerate(bw_values):
    plt.plot(t_range,kde[i](t_range),lw=2, label='bw = '+str(bw))
plt.xlim(-1,6)
plt.legend(loc='best')

请注意,较大的bw值会导致更平滑的pdf估计,但是(在本示例中)建议使用负值的成本是可能的,在此情况并非如此.

Note that large bw values result in a smoother pdf estimate, however, with the cost (in this example) of suggesting negative values are possible, which is not the case here.

这篇关于如何绘制事件到达间隔时间的概率密度函数(PDF)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆