-
-
Save benyi-mikara/c8945153387da3d25fd47202185a0f33 to your computer and use it in GitHub Desktop.
Negative Binomial
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 pandas as pd | |
import numpy as np | |
import pymc3 as pm | |
import pickle | |
with open('variables.pkl','rb') as picklefile: | |
storeno,dow,temperature,total_quantity,no_stores,no_dow = pickle.load(picklefile) | |
with pm.Model() as quantity_model_1: | |
alpha = pm.Uniform("alpha", lower=0, upper=10) | |
# Priors | |
sigma_a = pm.HalfCauchy('sigma_a', 1) | |
a = pm.HalfCauchy('a', beta=sigma_a, shape=no_stores) | |
b = pm.HalfCauchy('b', beta=1, shape=no_dow) | |
d = 0.0 | |
k = pm.Deterministic('k',var=b[dow]*pm.math.exp(d*temperature)) | |
y_hat = pm.Deterministic('y_hat',var=a[storeno]*k) | |
# Data likelihood | |
vol = pm.NegativeBinomial('vol', mu=y_hat, alpha=alpha, observed=total_quantity) | |
# Inference | |
trace = pm.sample() | |
for RV in quantity_model_1.basic_RVs: | |
print(RV.name, RV.logp(quantity_model_1.test_point) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment