在Python中实现贝叶斯层次建模

时间:2020-06-10 18:02:42

标签: machine-learning pymc3 pymc hierarchical-bayesian

我试图在不同的数据集上实现贝叶斯层次建模,然后我通过Internet搜索并通过Pymc3找到了该文档。

https://docs.pymc.io/notebooks/GLM-hierarchical.html

我想知道他们实际上是如何使用参数的。 Mu值,sigma值,为什么要使用这些值。如何确定?

以下是用于Radon数据集的代码。

with pm.Model() as hierarchical_model:
    # Hyperpriors for group nodes
    mu_a = pm.Normal('mu_a', mu=0., sigma=100)
    sigma_a = pm.HalfNormal('sigma_a', 5.)
    mu_b = pm.Normal('mu_b', mu=0., sigma=100)
    sigma_b = pm.HalfNormal('sigma_b', 5.)

    # Intercept for each county, distributed around group mean mu_a
    # Above we just set mu and sd to a fixed value while here we
    # plug in a common group distribution for all a and b (which are
    # vectors of length n_counties).
    a = pm.Normal('a', mu=mu_a, sigma=sigma_a, shape=n_counties)
    # Intercept for each county, distributed around group mean mu_a
    b = pm.Normal('b', mu=mu_b, sigma=sigma_b, shape=n_counties)

1 个答案:

答案 0 :(得分:0)

来自您的博客文章:

因此,我们假设截距α和斜率β来自以正态分布为中心的正态分布,正态分布以各自的均值μ为中心,且具有一定的标准偏差σ^ 2

这意味着该模型假设各县并不完全相似,但也并非完全独立。参数μ(μ)和σ^ 2(σ)表示每个县之间的相似度。如果我们阅读了您发布的文章的更多内容,我们会看到以下引用:

左栏中的后代具有丰富的信息。 mu_a告诉我们该组的平均(对数)ra水平。 mu_b告诉我们,没有地下室会显着降低ra水平(没有质量高于零)。

这就是mu_a和mu_b代表的内容。 Sigma_a和sigma_b将代表数据的方差。如果您不熟悉这些术语,则可能需要阅读Normal Distribution上的维基百科页面。

我对该算法并不熟悉,但是似乎他们只是通过选择随机数或他们知道通常是该算法的一个很好的起点来确定mu和sigma的值。 mu和sigma的值都将更改,以更好地拟合模型所看到的数据。