【问题标题】:Fitting data to a probability distribution, maybe skew normal?将数据拟合到概率分布,可能偏斜正态?
【发布时间】:2018-12-23 19:58:44
【问题描述】:

我正在尝试将我的数据拟合到某种概率分布,因此我可以根据该分布生成随机数。下面是数据点的样子,x 轴在数据值后面,y 轴在概率后面。

Data plot

它们看起来适合偏态正态分布,平均值约为 10^-4。该图的数据实际上是从原始数据集中分箱的。我尝试使用scipy.stats 库来拟合原始数据的偏斜法线,但这种拟合根本不起作用。

我想知道是否有人知道如何将它适合任何 PDF?我的情节中的数据如下(无法发布原始的原始数据,因为它太大了):

x = [2.0030289496413441e-07, 6.021220996561269e-07, 1.8100138940039783e-06, 5.4410065638820868e-06, 1.6355980761406714e-05, 4.916702516834233e-05, 0.00014779892439152631, 0.00044429212417263257, 0.0013355678494582283, 0.0040147942838919017, 0.012068704071088232, 0.036279223206999923, 0.10905744550124194, 0.32783299552460016, 0.98548496584223111, 2.9624248661943691, 8.9052206700550585, 26.769608940074498, 80.470994415019419, 241.90046842440222, 727.16681394735679, 2185.9055451626773, 6570.9586311220974, 19752.682098944373]

y (or P(x) in the diagram) = [2.2554525565554728e-05, 2.2554525565554728e-05, 3.1576335791776624e-05, 0.0013140978842667934, 0.00029833486088983759, 0.00083417571068968434, 0.0013023224717182351, 0.00030292744905932074, 0.00018784462533064236, 0.00015960011900197359, 5.231239486282394e-05, 4.8227744123750205e-05, 3.8972462681781172e-05, 2.9372389964277703e-05, 3.3001942979800356e-05, 2.8061790992628833e-05, 2.6056781088158009e-05, 2.522638138246609e-05, 2.4144908778509908e-05, 2.5086756895368843e-05, 2.3095834179128078e-05, 2.2554525565554745e-05, 2.2554525565554755e-05, 2.2554525565554728e-05]

【问题讨论】:

  • “我尝试使用 scipy.stats 库来适应原始数据的正常偏斜,但这种拟合根本不起作用。” 如果您展示了您尝试过的内容以及没有按您预期的方式工作的地方,也许有人可以帮助您。

标签: python scipy statistics


【解决方案1】:

您可以使用scipy.stats.skewnorm.fit(请参阅文档here)将数据拟合成偏正态分布。

skewnorm.fit 从数据中返回形状、位置和尺度参数的最大似然估计 (MLE)。

from scipy import stats

# define your dataset here

# let's make a sample with pre-defined parameters to demonstrate how it works
a, loc, scale = 1.6, -0.2, 3.2
data = stats.skewnorm(a, loc, scale).rvs(10000)

# estimate parameters of the sample
a_estimate, loc_estimate, scale_estimate = stats.skewnorm.fit(data)
print(a_estimate, loc_estimate, scale_estimate)

输出:

1.5784198343540448 -0.18066366859003175 3.1817350641737274

【讨论】:

    猜你喜欢
    • 2014-05-27
    • 2013-03-06
    • 1970-01-01
    • 2014-09-02
    • 2017-11-03
    • 1970-01-01
    • 1970-01-01
    • 2020-12-04
    • 1970-01-01
    相关资源
    最近更新 更多