Skip to content

Instantly share code, notes, and snippets.

@ashokc
Created January 26, 2019 18:07
Show Gist options
  • Save ashokc/d9ab722fbe249ecd1920e753a66494e8 to your computer and use it in GitHub Desktop.
Save ashokc/d9ab722fbe249ecd1920e753a66494e8 to your computer and use it in GitHub Desktop.
Train & Predict with LSTM
# Train and Predict with LSTM
train_labels = keras.utils.to_categorical(labels[train_indices], len(labelToName))
test_labels = keras.utils.to_categorical(labels[test_indices], len(labelToName))
early_stop = keras.callbacks.EarlyStopping(monitor='val_loss', min_delta=0, patience=5, verbose=2, mode='auto', restore_best_weights=False)
history = model.fit(x=train_x, y=train_labels, epochs=50, batch_size=32, shuffle=True, validation_data = (test_x, test_labels), verbose=2, callbacks=[early_stop])
predicted = model.predict(test_x, verbose=2)
predicted_labels = predicted.argmax(axis=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment