如何在贝叶斯模型中包含多个先验

2024-04-24 05:47:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试用Python进行贝叶斯回归。我已经为相同的结果(y)变量包括了多个先验值,但后验平均值似乎没有改变。有人能评论一下我的实现吗

import pymc3 as pm

formula = schooling_y_r5 ~ xvariable

with pm.Model() as normal_model:
    
    my_priors= {
        'Intercept': pm.Normal.dist(mu=0., sigma=100.),
        'schooling_y_r5': pm.Normal.dist(mu=14, sigma=3.8) ,
        'schooling_y_r5': pm.Normal.dist(mu=17, sigma=3.8) ,
        'schooling_y_r5': pm.Normal.dist(mu=7.8, sigma=3.8) ,
        'schooling_y_r5': pm.Normal.dist(mu=7.6, sigma=3.8) 
    }
    
   
    
    # Creating the model requires a formula and data (and optionally a family)
    pm.GLM.from_formula(formula, data = X_train, priors=my_priors)
    
    # Perform Markov Chain Monte Carlo sampling letting PyMC3 choose the algorithm
    normal_trace = pm.sample(draws=3000, chains = 2, tune = 4000)

Tags: andthemodelmydistassigmanormal