Advanced Deep Learning with Keras
Zach Deane Mayer
Data Scientist
from pandas import read_csv
games_season = read_csv('datasets/games_season.csv')
games_season.head()
team_1 team_2 home score_diff
0 3745 6664 0 17
1 126 7493 1 7
2 288 3593 1 7
3 1846 9881 1 16
4 2675 10298 1 12
games_tourney = read_csv('datasets/games_tourney.csv')
games_tourney.head()
team_1 team_2 home seed_diff score_diff
0 288 73 0 -3 -9
1 5929 73 0 4 6
2 9884 73 0 5 -4
3 73 288 0 3 9
4 3920 410 0 1 -9
in_data_1 = games_tourney['team_1']
in_data_2 = games_tourney['team_2']
in_data_3 = games_tourney['home']
pred = regular_season_model.predict([in_data_1, in_data_2, in_data_3])
games_tourney['pred'] = pred
games_tourney.head()
team_1 team_2 home seed_diff pred score_diff
0 288 73 0 -3 0.582556 -9
1 5929 73 0 4 0.707279 6
2 9884 73 0 5 1.364844 -4
3 73 288 0 3 0.699145 9
4 3920 410 0 1 0.833066 -9
games_tourney[['home','seed_diff','pred']].head()
home seed_diff pred
0 0 -3 0.582556
1 0 4 0.707279
2 0 5 1.364844
3 0 3 0.699145
4 0 1 0.833066
from tensorflow.keras.layers import Input, Dense
in_tensor = Input(shape=(3,))
out_tensor = Dense(1)(in_tensor)
from tensorflow.keras.models import Model
model = Model(in_tensor, out_tensor)
model.compile(optimizer='adam', loss='mae')
train_X = train_data[['home','seed_diff','pred']]
train_y = train_data['score_diff']
model.fit(train_X,train_y, epochs=10, validation_split=.10)
test_X = test_data[['home','seed_diff','pred']]
test_y = test_data['score_diff']
model.evaluate(test_X, test_y)
1066/1066 [==============================] - 0s 14us/step
9.11321775461451
Advanced Deep Learning with Keras