TransWikia.com

Embedding a categorical variable and concatenating with a numerical variable, in a many-to-one sequence problem with multiple features

Data Science Asked by LHS on April 24, 2021

I have a small data set where I track 4 variables across 4 time periods, 1 categorical and 1 numerical variable. Below is picture of data set that I am using:

enter image description here

  • cat1 – Categorical variable encoded
  • num1 – Numerical variable

Below is picture of my data set (to show the format; my X and Y is the same cause I am trying to learn how GRUs work and am not concerned much about the model accuracy).

enter image description here

Here is my GRU model code. It runs well and it predicts ok.

inputs = Input(shape=(4,2))
x = Bidirectional(GRU(256, activation='relu'))(inputs)
x = Dense(32, activation='relu')(x)
outputs = Dense(4)(x)
model = Model(inputs=inputs, outputs=outputs, name="func_loss_res")
model.summary()
plot_model(model, "my_first_model_with_shape_info.png", show_shapes=True)

model.compile(optimizer='adam', loss='mse')
my_callbacks = [tf.keras.callbacks.EarlyStopping(patience=10)]
print(X_train)
history = model.fit(X_train, Y_train, epochs=250, validation_split=0.25, batch_size=4, callbacks=my_callbacks)

My question is, if I were to Embed the cat1 variable say with 5 unique values and embedding size of 3 (I want to scale this model with 146 categories later and add 22 numerical variables), how can I concatenate cat1 and num1 to make it work for my given GRU? Any assistance is highly appreciated!

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP