This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Time Series Testing | |
import keras.callbacks | |
from keras.models import Sequential | |
from keras.layers.core import Dense, Activation, Dense, Dropout | |
from keras.layers.recurrent import LSTM | |
# Call back to capture losses | |
class LossHistory(keras.callbacks.Callback): | |
def on_train_begin(self, logs={}): | |
self.losses = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Code for Jupyter/IPython Notebook environment | |
from keras.models import Sequential | |
from keras.layers.core import TimeDistributedDense, Activation, Dropout | |
from keras.layers.recurrent import GRU | |
import numpy as np | |
from keras.utils.layer_utils import print_layer_shapes | |
%matplotlib inline | |
import matplotlib.pyplot as plt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import absolute_import | |
from __future__ import print_function | |
import numpy as np | |
from keras.preprocessing import sequence | |
from keras.optimizers import SGD, RMSprop, Adagrad, Adadelta | |
from keras.utils import np_utils | |
from keras.models import Sequential | |
from keras.layers.core import Dense, Dropout, Activation, TimeDistributedDense, Flatten, Permute, Reshape | |
from keras.layers.embeddings import Embedding | |
from keras.layers.recurrent import LSTM, GRU, SimpleRNN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
steps_ahead = 5 # how much steps ahead to predict | |
dim = 1 # dimension of the input series | |
X_multi = X # copy input sequence to the separate variable in order not to add garbage to the original sequence | |
for i in range(0, steps_ahead): | |
predicted = model_train_dict['model'].predict(X_multi, batch_size=batch_size) | |
X_multi = np.append(X_multi, np.reshape(predicted[-1:], (1, 1, dim)), axis=0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pandas as pd | |
def compute_market_prices(prices): | |
"""Compute market prices according to the trading competition recipe. | |
Parameters | |
---------- | |
prices : DataFrame |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
os.environ["KERAS_BACKEND"] = "tensorflow" | |
import numpy as np | |
from keras.models import Sequential | |
from keras.layers import Deconvolution2D | |
import warnings |