Two-output models

Advanced Deep Learning with Keras

Zach Deane-Mayer

Data Scientist

Simple model with 2 outputs

from tensorflow.keras.layers import Input, Concatenate, Dense
input_tensor = Input(shape=(1,))
output_tensor = Dense(2)(input_tensor)

Advanced Deep Learning with Keras

Simple model with 2 outputs

from tensorflow.keras.models import Model
model = Model(input_tensor, output_tensor)
model.compile(optimizer='adam', loss='mean_absolute_error')

Advanced Deep Learning with Keras

Fitting a model with 2 outputs

games_tourney_train[['seed_diff', 'score_1', 'score_2']].head()
   seed_diff  score_1  score_2
0         -3       41       50
1          4       61       55
2          5       59       63
3          3       50       41
4          1       54       63
X = games_tourney_train[['seed_diff']]
y = games_tourney_train[['score_1', 'score_2']]
model.fit(X, y, epochs=500)
Advanced Deep Learning with Keras

Inspecting a 2 output model

model.get_weights()
[array([[ 0.60714734, -0.5988793 ]], dtype=float32),
 array([70.39491, 70.39306], dtype=float32)]
Advanced Deep Learning with Keras

Evaluating a model with 2 outputs

X = games_tourney_test[['seed_diff']]
y = games_tourney_test[['score_1', 'score_2']]
model.evaluate(X, y)
11.528035634635021
Advanced Deep Learning with Keras

Let's practice!

Advanced Deep Learning with Keras

Preparing Video For Download...