Skip to content

Instantly share code, notes, and snippets.

@benyi-mikara
Created July 8, 2018 01:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benyi-mikara/c8945153387da3d25fd47202185a0f33 to your computer and use it in GitHub Desktop.
Save benyi-mikara/c8945153387da3d25fd47202185a0f33 to your computer and use it in GitHub Desktop.
Negative Binomial
Display the source blob
Display the rendered blob
Raw
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