%matplotlib inline
Last year, and for the second year in a row, Stephen Curry broke the NBA record for three pointers made in a season -- 286 -- besting his previous record of 272.
Through five games this year, Curry's made 28, putting him on pace to hit 459. I'm going to go out on a limb and say he won't make that many, but it's interesting to think about how many he will hit.
Thus far in his career, Curry's shot 44.2% from three.
Let's use pymc3 to set up our model and simulate the problem.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
from pymc3 import Model, Beta, Binomial, Uniform, Normal, Deterministic
import pymc3 as pm
seasons = pd.read_clipboard(sep=',')
seasons['Season'] = seasons['Season'].apply(lambda s: s.replace('★', '').strip())
seasons.set_index('Season', inplace=True)
seasons['3PA'].sum() / seasons['MP'].sum().astype(float)
0.18737685984102181
with Model() as model:
# setup our priors
avg_mins_played = seasons[:-1]['MP'].mean()
std_mins_played = seasons[:-1]['MP'].std()
minutes = Normal("minutes_played", mu=avg_mins_played, sd=std_mins_played)
three_attempts_per_min = seasons['3PA'].sum() / seasons['MP'].sum().astype(float)
attempts_per_minute = Binomial("attempts_per_minute", n=seasons['MP'].sum(),
p=three_attempts_per_min)
career_rate = seasons['3P'].sum() / seasons['3PA'].sum().astype(float)
success_rate = Binomial('success_rate', n=seasons['3PA'].sum(), p=career_rate)
threes_made_2016 = Deterministic("2016_threes", minutes * attempts_per_minute * success_rate)
with model:
start = pm.find_MAP()
step = pm.NUTS(state=start)
trace = pm.sample(1000, start=start, progressbar=True)
pm.traceplot(trace)
Assigned <class 'pymc3.step_methods.nuts.NUTS'> to minutes_played Assigned <class 'pymc3.step_methods.metropolis.Metropolis'> to attempts_per_minute Assigned <class 'pymc3.step_methods.metropolis.Metropolis'> to success_rate [-----------------100%-----------------] 1000 of 1000 complete in 0.6 sec