Skip to content

Instantly share code, notes, and snippets.

@alik604
Created July 28, 2020 01:17
Show Gist options
  • Save alik604/69548f99a9dda2d45c42db59e226cff0 to your computer and use it in GitHub Desktop.
Save alik604/69548f99a9dda2d45c42db59e226cff0 to your computer and use it in GitHub Desktop.
build_dataset LSTM.py
# make dataset to input
def build_dataset(time_series, seq_length):
dataX = []
dataY = []
for i in range(0, len(time_series) - seq_length):
_x = time_series[i:i + seq_length, :]
_y = time_series[i + seq_length, [-1]] # Next close price
print(_x, "->", _y)
dataX.append(_x)
dataY.append(_y)
return np.array(dataX), np.array(dataY)
@alik604
Copy link
Author

alik604 commented Aug 17, 2020

src

import numpy as np

def to_sequences(seq_size, obs):
    x = []
    y = []

    for i in range(len(obs)-SEQUENCE_SIZE-1):
        #print(i)
        window = obs[i:(i+SEQUENCE_SIZE)]
        after_window = obs[i+SEQUENCE_SIZE]
        window = [[x] for x in window]
        #print("{} - {}".format(window,after_window))
        x.append(window)
        y.append(after_window)
        
    return np.array(x),np.array(y)
    
    
SEQUENCE_SIZE = 25
x_train,y_train = to_sequences(SEQUENCE_SIZE,spots_train)
x_test,y_test = to_sequences(SEQUENCE_SIZE,spots_test)

print("Shape of training set: {}".format(x_train.shape))
print("Shape of test set: {}".format(x_test.shape))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment