Spaces:
Running
Running
File size: 1,128 Bytes
e59b179 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
from numpy import array
def project(time_step: int, test_data, model, days: int = 30):
x_input = test_data[len(test_data) - time_step :].reshape(1, -1)
temp_input = list(x_input)
temp_input = temp_input[0].tolist()
lst_output = []
n_steps = time_step
i = 0
pred_days = days
while i < pred_days:
if len(temp_input) > time_step:
x_input = array(temp_input[1:])
# print("{} day input {}".format(i,x_input))
x_input = x_input.reshape(1, -1)
x_input = x_input.reshape((1, n_steps, 1))
yhat = model.predict(x_input, verbose=0)
# print("{} day output {}".format(i,yhat))
temp_input.extend(yhat[0].tolist())
temp_input = temp_input[1:]
# print(temp_input)
lst_output.extend(yhat.tolist())
i = i + 1
else:
x_input = x_input.reshape((1, n_steps, 1))
yhat = model.predict(x_input, verbose=0)
temp_input.extend(yhat[0].tolist())
lst_output.extend(yhat.tolist())
i = i + 1
return lst_output
|