Single model for classification and regression

Advanced Deep Learning with Keras

Zach Deane-Mayer

Data Scientist

Build a simple regressor/classifier

from tensorflow.keras.layers import Input, Dense
input_tensor = Input(shape=(1,))
output_tensor_reg = Dense(1)(input_tensor)
output_tensor_class = Dense(1, activation='sigmoid')(output_tensor_reg)

Advanced Deep Learning with Keras

Make a regressor/classifier model

from tensorflow.keras.models import Model
model = Model(input_tensor, [output_tensor_reg, output_tensor_class])
model.compile(loss=['mean_absolute_error', 'binary_crossentropy'],
              optimizer='adam')

Advanced Deep Learning with Keras

Fit the combination classifier/regressor

X = games_tourney_train[['seed_diff']]
y_reg = games_tourney_train[['score_diff']]
y_class = games_tourney_train[['won']]
model.fit(X, [y_reg, y_class], epochs=100)

Advanced Deep Learning with Keras

Look at the model's weights

model.get_weights()

[array([[1.2371823]], dtype=float32), array([-0.05451894], dtype=float32), array([[0.13870609]], dtype=float32), array([0.00734114], dtype=float32)]

Advanced Deep Learning with Keras

Look at the model's weights

model.get_weights()

[array([[1.2371823]], dtype=float32), array([-0.05451894], dtype=float32), array([[0.13870609]], dtype=float32), array([0.00734114], dtype=float32)]
from scipy.special import expit as sigmoid
print(sigmoid(1 * 0.13870609 + 0.00734114))
0.5364470465211318
Advanced Deep Learning with Keras

Evaluate the model on new data

X = games_tourney_test[['seed_diff']]
y_reg = games_tourney_test[['score_diff']]
y_class = games_tourney_test[['won']]
model.evaluate(X, [y_reg, y_class])
[9.866300069455413, 9.281179495657208, 0.585120575627864]
Advanced Deep Learning with Keras

Now you try!

Advanced Deep Learning with Keras

Preparing Video For Download...