The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Ask
Anybody can ask a question
Answer
Anybody can answer
Vote
The best answers are voted up and moderated by our team

Prediction using the LSTM model for long-term has problems with the final step which is the generating of future predicted values

Prediction using the LSTM model for long-term has problems with the final step which is the generating of future predicted values

0
Votes
0
Answer

Hi, I’m working on research for temperature prediction using the LSTM model for long-term prediction but I faced some problems with the final step which is the generating of future predicted values. My historical temperature data range from (0.41°C to 40°C)  while the generated of future predicted values varying between (20°C to 30°C) which are not normal ( please see the attached image). I think there is a problem in my code (my code which covers the future predicted part is below).Please I need some help to solve this issue.
 
from sklearn.preprocessing import MinMaxScaler
#from sklearn.preprocessing import StandardScaler
scaler = MinMaxScaler()
scaler.fit(train)
train = scaler.transform(train)
test = scaler.transform(test)
#scaler=StandardScaler()
#scaler.fit(train)
#train = scaler.transform(train)
#test = scaler.transform(test)
 
scaler.fit(train)
train = scaler.transform(train)
 
time_steps = 450
n_features = 1
 
history = model.fit(
X_train, y_train,
epochs=7,
batch_size=16,
validation_split=0.1,
verbose=1,
shuffle=False
)
 
pred_list = [ ]
batch = train[-time_steps:].reshape((1, time_steps, n_features))
for i in range(time_steps):
pred_list.append(model.predict(batch)[0])
batch = np.append(batch[:,1:,:],[[pred_list[i]]],axis=1)
 
from pandas.tseries.offsets import DateOffset
add_dates = [df.index[-1] + DateOffset(days=x) for x in range(0,452) ]
future_dates = pd.DataFrame(index=add_dates[1:],columns=df.columns)
 
df_predict = pd.DataFrame(scaler.inverse_transform(pred_list),
index=future_dates[-time_steps:].index, columns=[‘Prediction’])
df_proj = pd.concat([df,df_predict], axis=1)
 
plt.figure(figsize=(20, 5))
plt.plot(df_proj.index, df_proj[‘Air temperature | (\’C)’])
plt.plot(df_proj.index, df_proj[‘Prediction’], color=’r’)
plt.legend(loc=’best’, fontsize=’xx-large’)
plt.ylabel(‘Temperature °C’)
plt.xlabel(‘Time Step’)
plt.legend()
plt.show()
 
 
Thank you and sorry for any inconvenience.
1- historical data and future predicted values

No answers so far.