I have simple data set like dataset
and I want to prepare that for time series prediction with deep learning. for this purpose I have a function like function I am not sure about fnctionality of this function. Do you have replacement or can you make me sure for about the functionality of this function?
For time series predictions, the label is part of the data itself. The code works for this sample as well. The function will essentially carve out windows of data from the dataset using that as X (input to your NN model) and the subsequent data as y (label to your model).
As an example you can decide to make a window of 2 and have the model predict the next value.
So, first input becomes X: 34, 37
and the label for it y: 29
. Next input X: 37, 29 and y: 34
and so on and so forth.
import numpy as np
def to_supervised(train, n_input, n_out):
data = train
X, y = list(), list()
in_start = 0
for _ in range(len(data)):
in_end = in_start + n_input
out_end = in_end + n_out
if out_end <= len(data):
x_input = data[in_start:in_end]
x_input = x_input.reshape((len(x_input)))
X.append(x_input)
y.append(data[in_end:out_end])
in_start += 1
return np.array(X), np.array(y)
issued = np.array([34, 37, 29, 34, 45])
to_supervised(issued, 2, 1)
Output:
(array([[34, 37],
[37, 29],
[29, 34]]),
array([[29],
[34],
[45]]))