Last active
March 11, 2018 13:31
-
-
Save tigershen23/8eb919b82aed4132c7c84e7eecfca9fd to your computer and use it in GitHub Desktop.
Example from Ch 4 of Bayesian Methods for Hackers.
This file contains hidden or 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 | |
def posterior_upvote_ratio(upvotes, downvotes, samples = 20000): | |
“”” | |
This function accepts the number of upvotes and downvotes a particular submission recieved, | |
and the number of posterior samples to return to the user. Assumes a uniform prior. | |
“”” | |
N = upvotes + downvotes | |
with pm.Model() as model: | |
upvote_ratio = pm.Uniform(“upvote_ratio”, 0, 1) # (1) | |
observations = pm.Binomial( “obs”, N, upvote_ratio, observed=upvotes) # (2) | |
trace = pm.sample(samples, step=pm.Metropolis()) # (3) | |
burned_trace = trace[int(samples/4):] # (4) | |
return burned_trace[“upvote_ratio”] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment