'How can I get the results of model.predict back into my pandas DataFrame?

The implementation of my model can be seen below.


feature_names_activity = ['org:resource', 'lifecycletransition', 'case:concept:name',
                          'case:AMOUNT_REQ', 'Duration', 'day', 'hour', 'prev_activity', 'position', 
                          'A_ACCEPTED', 'A_ACTIVATED', 'A_APPROVED', 'A_CANCELLED', 'A_DECLINED', 'A_FINALIZED', 
                          'A_PARTLYSUBMITTED', 'A_PREACCEPTED', 'A_REGISTERED', 'A_SUBMITTED', 'O_ACCEPTED', 'O_CANCELLED',
                          'O_CREATED', 'O_DECLINED', 'O_SELECTED', 'O_SENT', 'O_SENT_BACK', 'W_Afhandelen leads', 
                          'W_Beoordelen fraude', 'W_Completeren aanvraag', 'W_Nabellen incomplete dossiers', 'W_Nabellen offertes',
                          'W_Valideren aanvraag', 'W_Wijzigen contractgegevens']

features_activity = df_training[feature_names_activity]

features_activity_test = df_test[feature_names_activity]

def get_basic_model():
      model = tf.keras.Sequential([
        normalizer_activity,
        tf.keras.layers.Dense(256, activation='relu'),
        tf.keras.layers.Dense(256, activation='relu'),
        tf.keras.layers.Dense(256, activation='relu'),
        tf.keras.layers.Dense(256, activation='relu'),
        tf.keras.layers.Dense(256, activation='relu'),
        tf.keras.layers.Flatten(),
        tf.keras.layers.Dense(24)
      ])
    
      model.compile(optimizer='adam',
                    loss='sparse_categorical_crossentropy',
                    metrics=['accuracy'])
      return model
        
    model = get_basic_model()
    model.fit(features_activity, target_activity, epochs=5, batch_size=181138)

My goal is adding a prediction column to my DataFrame that gives the prediction for each row (i.e. df.loc[0][prediction] = predicted_activity). If I run model.predict(df.loc[0][feature_names_activity]), I get a 24x33 table (with 24 being the amount of different activities and 33 being the amount of features). How can I read this table to get the prediction and how can I return a prediction column for my df?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source