Skip to content

Instantly share code, notes, and snippets.

@steveway
Created November 21, 2017 15:37
Show Gist options
  • Select an option

  • Save steveway/49814c29d9bebd7fcea2f6918fbb2c7a to your computer and use it in GitHub Desktop.

Select an option

Save steveway/49814c29d9bebd7fcea2f6918fbb2c7a to your computer and use it in GitHub Desktop.
import numpy as np
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import LSTM
# This does work by using only one sample:
data = [[0,0,0,0,0,0,0,0,0,2,1]]
data = np.array(data, dtype=float)
target = [0,0,0,0,0,0,0,0,2,1,0]
target = np.array(target, dtype=float)
data = data.reshape((1, 1, 11)) # Single batch, 1 time steps, 11 dimentions
target = target.reshape((-1, 11)) # Corresponds to shape (None, 11)
# Build Model
model = Sequential()
model.add(LSTM(11, input_shape=(1, 11), unroll=False))
model.add(Dense(11))
model.compile(loss='mean_absolute_error', optimizer='adam')
model.fit(data, target, nb_epoch=1000, batch_size=1, verbose=2)
# Do the output values match the target values?
predict = model.predict(data)
print(repr(data))
print(repr(predict))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment