When training my network, I have a multi label classification problem in which I convert the class labels into one hot encoding.
After training the model, and generating predictions - keras simply outputs an array of values without specifying the class label.
What is best practice to merge these, so my API can return meaningful results to the consumer?
Example
y = pd.get_dummies(df_merged.eventId)
y
2CBC9h3uple1SXxEVy8W GiiFxmfrUwBNMGgFuoHo e06onPbpyCucAGXw01mM
12 1 0 0
13 1 0 0
14 1 0 0
prediction = model.predict(pred_test_input)
prediction
array([[0.5002058 , 0.49697363, 0.50251794]], dtype=float32)
Desired outcome:
{results: { 2CBC9h3uple1SXxEVy8W: 0.5002058, ...}
EDIT: Adding model as per comment - but this is just a toy model.
model = Sequential()
model.add(
Embedding(
input_dim=embeddings_index.shape[0],
output_dim=embeddings_index.shape[1],
weights=[embeddings_index],
input_length=MAX_SEQ_LENGTH,
trainable=False,
)
)
model.add(LSTM(300))
model.add(Dense(units=len(y.columns), activation='sigmoid'))
model.compile(loss='categorical_crossentropy', optimizer='sgd', metrics=['accuracy'])
EDIT 2 - adding y.
So my y
is in the following format:
eventId
123
123
234
...
I then use y = pd.get_dummies(df_merged.eventId)
to convert this into something the model can consume and would like to append the eventIds back to the predictions.