Dear Giora,
Stunning work on combining neural networks with mixed effects models! I'm interested in applying this to a binary classification task.
Since I couldn't find an example that uses mode 'glmm' among your notebooks, I worked through the imdb.ipynb notebook with the following adjustments added throughout the script.
# make y binary
imdb = imdb.assign(
score = lambda dataframe: dataframe['score'].map(lambda score: 1 if score >= 7 else 0)
)
# specify mode
mode = 'glmm'
# Model adjustments, though this is not critical here
y_pred_output = Dense(1, activation = 'sigmoid')(out_hidden)
optimizer = keras.optimizers.Adam(learning_rate=0.001)
model.compile(optimizer= optimizer)
Running the notebook, I receive the following error:
ValueError: dimension mismatch
I think the problem stems from the calculation of 'b_hat'. In 'calc_b_hat.py', lines 99 to 129, 'b_hat' seems to be calculated only for 'z0', not for 'z1' as well.
Then in 'nn.py', lines 532 to 533 produce the error message:
y_pred = model.predict([X_test[x_cols], dummy_y_test] + X_test_z_cols).reshape(
X_test.shape[0]) + Z_test @ b_hat
Since qs > 1 (2 in this case), Z_test combines the levels/categories of both z0 and z1. However, the length of b_hat is qs[0], i.e., the levels/categories in z0. The length of b_hat should be qs[0]+qs[1], no? Hence the dimension mismatch.
Should lines 99 to 129 in 'calc_b_hat' be adjusted to include an outermost loop through range(qs), then in the end stacking the b_hats of both variables?
Appreciate any help on this! Do you happen to have a working example with mode 'glmm'?
enhancement