简体   繁体   English

有什么简单的方法可以将概率质量 function 拟合到给定的数据集?

[英]Is there any easy way to fit probability mass function to a given dataset?

Assume we have a list of numbers (samples)假设我们有一个数字列表(样本)

data = [0,0,1,2,3]数据 = [0,0,1,2,3]

I would like to fit a probability mass function for this dataset, in such a way that if I do something like我想为这个数据集拟合概率质量 function,如果我做类似的事情

pmf.fit(data) pmf.fit(数据)

and by executing something like并通过执行类似

pmf.eval(0) pmf.eval(0)

I get我明白了

0.2 0.2

as return作为回报

and

by executing通过执行

pmf.eval(-1) pmf.eval(-1)

I get我明白了

0 0

as return.作为回报。

Note that I am working with a discrete random variable here, so I am not fitting a pdf...请注意,我在这里使用的是离散随机变量,所以我不适合 pdf...

I finally figured out myself我终于想通了自己

random_array = [0,0,1,2,3] random_array = [0,0,1,2,3]

unique, counts = np.unique(random_array, return_counts=True)独特的,计数 = np.unique(random_array,return_counts = True)

random_variable = sp.stats.rv_discrete(a = 0, b = np.inf, values = (unique, counts/np.sum(counts))) random_variable = sp.stats.rv_discrete(a = 0, b = np.inf, values = (unique, counts/np.sum(counts)))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM