pymc icon indicating copy to clipboard operation
pymc copied to clipboard

PPC with the Hierarchical model for Rugby prediction exam[;e

Open MostlyHarmless420 opened this issue 10 years ago • 5 comments

I've been experimenting with PPC on the hierarchical model for rugby prediction example to see if I can if it can be used to predict fictional games.

First, I think there is a minor mistake in the example. Where home_theta = tt.exp(intercept + home + atts[away_team] + defs[home_team]) it should be: home_theta = tt.exp(intercept + home + atts[home_team] + defs[away_team])

Second, when I run sample_ppc after replacing the home_team/away_team values, I receive the number of results that was used 'train'/sample the model, not the output expected:

I split the data between train and test, and encapsulate train data in the shared theano object.

df_test = df[:5]
df_train = df[5:100]
home_team = shared(df_train.i_home.values)
away_team = shared(df_train.i_away.values)

After sampling the data I replace the data in the shared theano object with the new data.

home_team = shared(df_test.i_home.values)
away_team = shared(df_test.i_away.values)
ppc = pm.sample_ppc(trace, model=model, samples=500)

The number of results I get are larger than I expect: ppc['home_points'].shape (500, 95)

MostlyHarmless420 avatar Feb 29 '16 13:02 MostlyHarmless420

Hi Shaun, I'll fix up that error when I next can.

I see nothing a priori wrong with your approach. Home_Points could be the total number of points scored in one game if I remember correctly.

I'll check.

On Mon, Feb 29, 2016 at 2:42 PM, ShaunBristol [email protected] wrote:

I've been experimenting with PPC on the hierarchical model for rugby prediction example to see if I can if it can be used to predict fictional games.

First, I think there is a minor mistake in the example. Where home_theta = tt.exp(intercept + home + atts[away_team] + defs[home_team]) it should be: home_theta = tt.exp(intercept + home + atts[home_team] + defs[away_team])

Second, when I run sample_ppc after replacing the home_team/away_team values, I receive the number of results that was used 'train'/sample the model, not the output expected:

I split the data between train and test, and encapsulate train data in the shared theano object.

df_test = df[:5] df_train = df[5:100] home_team = shared(df_train.i_home.values) away_team = shared(df_train.i_away.values)

After sampling the data I replace the data in the shared theano object with the new data.

home_team = shared(df_test.i_home.values) away_team = shared(df_test.i_away.values) ppc = pm.sample_ppc(trace, model=model, samples=500)

The results i get are larger than I expect: ppc['home_points'].shape (500, 95)

— Reply to this email directly or view it on GitHub https://github.com/pymc-devs/pymc3/issues/1001.

Peadar Coyle Skype: springcoilarch www.twitter.com/springcoil peadarcoyle.wordpress.com

springcoil avatar Feb 29 '16 14:02 springcoil

Hi, Thanks for responding. Home points is the score for the home side. However, the shape I would expect the results from sample_ppc would reflect the testing data (of 5 entries) which would be (500, 5). Instead I get (500, 95) which reflects the training data (95 entries).

MostlyHarmless420 avatar Feb 29 '16 15:02 MostlyHarmless420

home_team = shared(df_test.i_home.values)
away_team = shared(df_test.i_away.values)
ppc = pm.sample_ppc(trace, model=model, samples=500)

To set values you'd use home_team.set_value() rather than just instantiating a new shared object.

twiecki avatar Feb 29 '16 18:02 twiecki

Thanks, that was the problem.

MostlyHarmless420 avatar Mar 01 '16 02:03 MostlyHarmless420

You could add that as an example to the Notebook if you wanted Shaun or even in a separate example.

springcoil avatar Mar 01 '16 08:03 springcoil