#!/usr/bin/env python # coding: utf-8 # In[2]: get_ipython().run_line_magic('matplotlib', 'inline') import numpy as np import pandas as pd import pymc3 as pm import seaborn as sns # In[3]: k = 1000 n = 100 fake_data = np.random.random((n, k+1)) y = (fake_data[:, 0] > 0.5).astype(int) X = fake_data[:, 1:] # In[4]: y[:10] # In[6]: X[:10] # In[7]: import theano.tensor as tt invlogit = lambda x: 1/(1 + tt.exp(-x)) with pm.Model() as logistic_model: β = pm.Normal('β', 0, sd=10000, shape=k) π = invlogit(tt.dot(X, β)) likelihood = pm.Bernoulli('likelihood', π, observed=y) # In[10]: with logistic_model: tr = pm.sample(10000, step=pm.Metropolis()) # In[11]: pm.summary(tr[-1000:])