In [1]:
from keras.layers.core import Dense, Activation, Dropout
from keras.layers.recurrent import LSTM
from keras.models import Sequential
import lstm, time


Using TensorFlow backend.

In [3]:
#loading the Data.
X_train, y_train, X_test, y_test = lstm.load_data('data/sp500.csv', 50, True)

In [4]:
#building Model
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')

print('compilation time:', time.time() - start)


compilation time: 0.027061939239501953

In [5]:
#Train the model
model.fit(
    X_train,
    y_train,
    batch_size=512,
    nb_epoch=1,
    validation_split=0.05)


Train on 3522 samples, validate on 186 samples
Epoch 1/1
3522/3522 [==============================] - 8s - loss: 0.0023 - val_loss: 0.0011
Out[5]:
<keras.callbacks.History at 0x11fb02a90>

In [6]:
print(lstm.plot_results_multiple)


<function plot_results_multiple at 0x10e33f598>

In [7]:
#plot results
predictions = lstm.predict_sequences_multiple(model, X_test, 50, 50)
lstm.plot_results_multiple(predictions, y_test, 50)