【问题标题】:How to fit the best probability distribution model to my data in python?如何在 python 中将最佳概率分布模型拟合到我的数据?
【发布时间】:2019-10-30 05:20:06
【问题描述】:

我有大约 20,000 行这样的数据,

Id | value
1    30
2    3
3    22
..
n    27

我对我的数据进行了统计,平均值 33.85,中位数 30.99,最小值 2.8,最大值 206,95% 置信区间 0.21.. 所以大多数值在 33 左右,并且有一些异常值(一点点).. 所以这似乎是一个长尾分布。

我对发行版和 python 都是新手,我尝试了 class fitter https://pypi.org/project/fitter/ 来尝试 Scipy 包中的许多发行版,并且 loglaplace 发行版显示出最低的错误(虽然不是很明白)。

我阅读了该线程中的几乎所有问题,并得出了两种方法 (1) 拟合分布模型,然后在我的模拟中绘制随机值 (2) 计算不同组值的频率,但此解决方案不会例如,值大于 206。

如果我的数据是值(数字),那么在我的模拟中我需要绘制数字时,在 python 中将分布拟合到我的数据的最佳方法是什么。随机数必须与我的数据具有相同的模式。我还需要通过绘制我的数据和模型曲线来验证模型是否能够很好地呈现我的数据。

【问题讨论】:

    标签: python-3.x scipy simulation distribution


    【解决方案1】:

    一种方法是根据贝叶斯信息标准(称为 BIC)选择最佳模型。 OpenTURNS 实现了一种自动选择方法 (see doc here)。

    假设你有一个数组x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],这里有一个简单的例子:

    import openturns as ot
    # Define x as a Sample object. It is a sample of size 11 and dimension 1
    sample = ot.Sample([[xi] for xi in x])
    
    # define distributions you want to test on the sample
    tested_distributions = [ot.WeibullMaxFactory(), ot.NormalFactory(), ot.UniformFactory()]
    
    # find the best distribution according to BIC and print its parameters
    best_model, best_bic = ot.FittingTest.BestModelBIC(sample, tested_distributions)
    print(best_model)
    >>> Uniform(a = -0.769231, b = 10.7692)
    

    【讨论】:

    • 您可以使用GetContinuousUniVariateFactories 创建所有单变量工厂的列表,但这可能会返回Histogram 分布。在某些情况下,这可能会令人失望。
    猜你喜欢
    • 2014-05-27
    • 1970-01-01
    • 2018-12-23
    • 2019-07-26
    • 1970-01-01
    • 2016-02-03
    • 1970-01-01
    • 2014-11-14
    • 2019-10-20
    相关资源
    最近更新 更多