text_html_output_1.png
from keras.layers.core import Dense, Activation, Dropout

from keras.layers.recurrent import LSTM

from keras.models import Sequential

import numpy as np # linear algebra

import time #helper libraries

def create_dataset(dataset, look_back=1):
    dataX, dataY = ([], [])
    for i in range(len(dataset) - look_back - 1):
        a = dataset[i:i + look_back, 0]
        dataX.append(a)
        dataY.append(dataset[i + look_back, 0])
    return (np.array(dataX), np.array(dataY))

trainX = np.reshape(trainX, (trainX.shape[0], 1, trainX.shape[1]))
testX = np.reshape(testX, (testX.shape[0], 1, testX.shape[1]))

model = Sequential()
model.add(LSTM(input_dim=1, output_dim=50, return_sequences=True))
model.add(Dropout(0.2))
model.add(LSTM(100, return_sequences=False))
model.add(Dropout(0.2))
model.add(Dense(output_dim=1))
model.add(Activation('linear'))
start = time.time()
model.compile(loss='mse', optimizer='rmsprop')

model.fit(trainX, trainY, batch_size=128, nb_epoch=10, validation_split=0.1)