使数据适合所有可能的分布并返回最佳拟合 [英] Fit data to all possible distributions and return the best fit
本文介绍了使数据适合所有可能的分布并返回最佳拟合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个样本数据,我想要获得最合适的分布.我有几个链接,建议我可以从scipy.stats
导入分布,但随后我不了解之前的数据类型.我想要一个类似于MATLAB
中的allfitdist()
的东西,它试图使数据适合大约20个分布并返回最佳拟合.
I have a sample data and I want to get the best fit distribution. I have got couple of links which suggest that I can import the distributions from scipy.stats
, but then I am not aware of the type of data before hand. I want something similar to allfitdist()
in MATLAB
which tries to fit data to around 20 distributions and returns the best fit.
allfitdist()
的链接:任何帮助都是非常重要的.谢谢.
Any help is highly appreciable. Thanks.
推荐答案
You can just create a list of all available distributions in scipy. An example with two distributions and random data:
import numpy as np
import scipy.stats as st
data = np.random.random(10000)
distributions = [st.laplace, st.norm]
mles = []
for distribution in distributions:
pars = distribution.fit(data)
mle = distribution.nnlf(pars, data)
mles.append(mle)
results = [(distribution.name, mle) for distribution, mle in zip(distributions, mles)]
best_fit = sorted(zip(distributions, mles), key=lambda d: d[1])[0]
print 'Best fit reached using {}, MLE value: {}'.format(best_fit[0].name, best_fit[1])
这篇关于使数据适合所有可能的分布并返回最佳拟合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文