<jupyter_start><jupyter_text>Linear regression<jupyter_code>endog = d['height']
exog = sm.add_constant(d['weight'])

mod = sm.OLS(endog, exog)
L = mod.fit()
L.summary()
sns.regplot(data=d, x='weight', y='height', ci=None, 
            scatter_kws={'color': 'lightblue'},
            line_kws={'color': 'r', 'linewidth': 3})
plt.show()<jupyter_output><empty_output><jupyter_text>Bayesian regression<jupyter_code>x = theano.shared(d['weight'].values)
y = theano.shared(d['height'].values)
nIter = 1000
nChains = 4
nWarmup = 1000
with pm.Model() as model:
    alpha = pm.Normal('alpha', 170, 100)
    beta = pm.Normal('beta', 0, 20)
    sigma = pm.HalfCauchy('sigma', beta=20)
    
    y = pm.Normal('y', mu=alpha + beta * x, sigma=sigma, observed=y)

    trace = pm.sample(nIter, tune=nWarmup, chains=nChains,
                     cores=4, return_inferencedata=True,
                     random_seed=1450154626)<jupyter_output>Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (4 chains in 4 jobs)
NUTS: [sigma, beta, alpha]<jupyter_text>Diagnostics<jupyter_code># notice that the values for alpha and beta are the same as 
# the ones estimated using `statsmodels`
with model:
    print(pm.summary(trace).round(2))
arviz.plot_trace(trace['posterior'])
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1517189835575486, 'fraction_numerical': 0.026158445440956652, 'mean_word_length': 4.510288065843621, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '514359', 'license': 'MIT', 'n_tokens_mistral': 526, 'n_tokens_neox': 484, 'n_words': 100, 'path': 'lec08-regression.ipynb', 'repo_name': 'K-Paks/BayesCog_Wien_py', 'size': '1338'}