如何根据经验分布函数制作样本 [英] How to make a sample from the empirical distribution function

查看:149
本文介绍了如何根据经验分布函数制作样本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Python上实现非参数自举.它需要获取一个样本,从中构建经验分布函数,然后从此edf生成一堆样本.我该怎么做? 在scipy中,如果您知道描述该函数的确切公式,我只会发现如何创建自己的分布函数,但是我只有一个edf.

I'm trying to implement the nonparametric bootstrapping on Python. It requires to take a sample, build an empirical distribution function from it and then to generate a bunch of samples from this edf. How can I do it? In scipy I found only how to make your own distribution function if you know the exact formula describing it, but I have only an edf.

推荐答案

通过对样本进行排序得到的edf:

The edf you get by sorting the samples:

N = samples.size
ss = np.sort(samples) # these are the x-values of the edf
                      # the y-values are 1/(2N), 3/(2N), 5/(2N) etc.
edf = lambda x: np.searchsorted(ss, x) / N

但是,如果您只想重新采样,则只需以相等的概率从样本中抽取样本即可.

However, if you only want to resample then you simply draw from your sample with equal probability and replacement.

如果您不喜欢这种步进式",则可以使用某种插值法获得平滑分布.

If this is too "steppy" for your liking, you can probably use some kind of interpolation to get a smooth distribution.

这篇关于如何根据经验分布函数制作样本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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