Skip to content

Instantly share code, notes, and snippets.

@mratsim
Created September 28, 2018 18:28
Show Gist options
  • Save mratsim/9af51fab4c25d381db622d69d7951e96 to your computer and use it in GitHub Desktop.
Save mratsim/9af51fab4c25d381db622d69d7951e96 to your computer and use it in GitHub Desktop.
train_test_split for sequence predictions
def make_input_seqs(data, seq_len, train_split=0.9):
seq_len = seq_len + 1
result = []
for index in range(len(data) - seq_len):
result.append(data[index: index + seq_len, :])
result = np.array(result)
train_ind = round(train_split * result.shape[0])
train = result[:int(train_ind), :, :]
x_train = train[:, :-1, :]
y_train = train[:, -1, :]
x_test = result[int(train_ind):, :-1, :]
y_test = result[int(train_ind):, -1, :]
return [x_train, y_train, x_test, y_test]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment