Last active
August 29, 2015 14:21
-
-
Save springcoil/bdb049278f7646d2eac2 to your computer and use it in GitHub Desktop.
A Bayesian model for myself to debug - PyData Berlin
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
g = simuls.groupby('Team') | |
season_hdis = pd.DataFrame({'points_lower': g.points.quantile(.05), | |
'points_upper': g.points.quantile(.95), | |
'goals_for_lower': g.gf.quantile(.05), | |
'goals_for_median': g.gf.median(), | |
'goals_for_upper': g.gf.quantile(.95), | |
'goals_against_lower': g.ga.quantile(.05), | |
'goals_against_upper': g.ga.quantile(.95), | |
}) | |
season_hdis = pd.merge(season_hdis, df_observed, left_index=True, right_on='Team') | |
column_order = ['Team', 'points_lower', 'Points', 'points_upper', | |
'goals_for_lower', 'Points_For', 'goals_for_median', 'goals_for_upper', | |
'goals_against_lower', 'Points_Against', 'goals_against_upper',] | |
season_hdis = season_hdis[column_order] | |
season_hdis['relative_goals_upper'] = season_hdis.goals_for_upper - season_hdis.goals_for_median | |
season_hdis['relative_goals_lower'] = season_hdis.goals_for_median - season_hdis.goals_for_lower | |
season_hdis = season_hdis.sort_index(by='Points_For') | |
season_hdis = season_hdis.reset_index() | |
season_hdis['x'] = season_hdis.index + .5 | |
season_hdis | |
fig, axs = plt.subplots(figsize=(10,6)) | |
axs.scatter(season_hdis.x, season_hdis.GF, c=sns.palettes.color_palette()[4], zorder = 10, label='Actual Goals For') | |
axs.errorbar(season_hdis.x, season_hdis.goals_for_median, | |
yerr=(season_hdis[['relative_goals_lower', 'relative_goals_upper']].values).T, | |
fmt='s', c=sns.palettes.color_palette()[5], label='Simulations') | |
axs.set_title('Actual Points For, and 90% Interval from Simulations, by Team') | |
axs.set_xlabel('Team') | |
axs.set_ylabel('Points Scored') | |
axs.set_xlim(0, 20) | |
axs.legend() | |
_= axs.set_xticks(season_hdis.index + .5) | |
_= axs.set_xticklabels(season_hdis['Team'].values, rotation=45) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment