Created
February 11, 2021 19:10
-
-
Save juangesino/022d616c8ba1665fa6cf437910430ca7 to your computer and use it in GitHub Desktop.
Bayesian Weight Loss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pymc3 as pm | |
with pm.Model() as model_1: | |
alpha = pm.Normal("alpha", mu=70, sigma=8) | |
beta = pm.Normal("beta", mu=0, sigma=1) | |
weight = pm.Deterministic("weight", alpha + beta * X) | |
noise = pm.HalfNormal("noise", sigma=1) | |
likelihood = pm.Normal("likelihood", mu=weight, sigma=noise, observed=Y) | |
trace_1 = pm.sample(tune=1500) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import statsmodels.api as sm | |
X_ols = sm.add_constant(X) | |
model = sm.OLS(Y, X_ols) | |
results = model.fit() | |
model.data.xnames = ["alpha", "beta"] | |
print(results.summary()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print("Pr(Weight > 68) =", np.mean(alpha_samples + beta_samples * max(X) > 68)) | |
# => Pr(Weight > 68) = 0.083 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment