Skip to content

Instantly share code, notes, and snippets.

@jetnew
Created June 6, 2019 12:19
Show Gist options
  • Save jetnew/79311e562e57bc59f0ac510bf52ae58a to your computer and use it in GitHub Desktop.
Save jetnew/79311e562e57bc59f0ac510bf52ae58a to your computer and use it in GitHub Desktop.
LSTM Forecasting using Keras
from keras.models import Sequential
from keras.layers import LSTM, Dense
from sklearn.metrics import mean_squared_error
timesteps = window_size-1
n_features = 1
model = Sequential()
model.add(LSTM(16, activation='relu', input_shape=(timesteps, n_features), return_sequences=True))
model.add(LSTM(16, activation='relu'))
model.add(Dense(1))
model.compile(optimizer='adam', loss='mse')
model.fit(X_train, y_train, epochs=30, batch_size=32)
y_pred = model.predict(X_test)
print("MSE:", mean_squared_error(y_test, y_pred))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment