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.
Hi Fahad,
could you indicate as to which course and which lecture this is related to? Thanks in advance.
Best,
The 365 Team