Created
August 28, 2013 01:50
-
-
Save megafaunasoft/6361250 to your computer and use it in GitHub Desktop.
pymc simulated data
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
from pymc import * | |
import numpy as np | |
import matplotlib.pyplot as pyplot | |
from pprint import pprint | |
#----------------------------------------------------------------------------------------- | |
# Simulated data | |
# | |
def simulated(N, weekday_mean, weekend_mean, click_mean, conversion_rate): | |
days = np.tile([0,0,0,0,0,1,1], np.ceil(N/7.))[:N] | |
installs = np.zeros(N) | |
installs[days==0] = rpoisson(weekday_mean, size=sum(days==0)) | |
installs[days==1] = rpoisson(weekend_mean, size=sum(days==1)) | |
# 0.1 installs per click | |
clicks = rpoisson(click_mean, size=N) # clicks | |
installs += [rpoisson(c*conversion_rate) for c in clicks] | |
assert len(set(arr.shape for arr in [installs, clicks, days])) == 1 | |
return installs, clicks, days | |
installs, clicks, days = simulated(1000, 10, 20, 20, 0.1) | |
pyplot.bar(range(len(installs)), np.where(days==0, installs, 0), color='#339988') | |
pyplot.bar(range(len(installs)), np.where(days==1, installs, 0), color='#dd7766') | |
pyplot.plot(range(len(installs)), clicks) | |
pyplot.savefig("installs.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment