How can I predict the following value of time series using Tensorflow predict method?

Viewed 787

I am wondering how to predict and get future time series data after model training. I would like to get the values after N steps. I wonder if the time series data has been properly learned and predicted. How do I do this right to get the following(next) value? I want to get the next value using model.predict or similar.

I have x_test and x_test[-1] == t So, the meaning of the next value is t+1, t+2, .... t+n. In this example I want to get t+1, t+2 ... t+n

First

I tried using stock index data

inputs = total_data[len(total_data) - forecast - look_back:]
inputs = scaler.transform(inputs)
X_test = []
for i in range(look_back, inputs.shape[0]):
    X_test.append(inputs[i - look_back:i])
X_test = np.array(X_test)
predicted = model.predict(X_test)

but the result is like below

enter image description here

The results from X_test[-20:] and the following 20 predictions looks like same. I'm wondering if it's the correct method to train and predicted value and also if the result was correct.

full source

The method I tried first did not work correctly.

Second

I realized something is wrong, I tried using another official data so I used the time series in the Tensorflow tutorial to practice training the model.

a = y_val[-look_back:] 
for i in range(N-step prediction): #predict a new value n times.
    tmp = model.predict(a.reshape(-1, look_back, num_feature)) #predicted value     
    a = a[1:] #remove first     
    a = np.append(a, tmp) #insert predicted value

The results were predicted in a linear regression shape very differently from the real data.

2

Output a linear regression abnormal that is independent of the real data:

full source (After the 25th line is my code.)

I'm really very curious that How can I predict the following value of time series using Tensorflow predict method

I'm not wondering if this works or not theoretically. I'm just wondering how to get the following n steps using the predict method.

Thank you for reading the long question. I seek advice about your priceless opinion.

1 Answers

"lstm" is normaly used to predict 3D data => target which input has same time frame number(n , t ,f) "n" for data number "t" for frame number , "f" for feature number

what you want to predict is 1D data => target which is (t ,f )
when you have f = 0 then you can only use F(t) => y if you can estimate function F then u can get y . NN can't help here

Related