如何解决使用双向LSTM进行长期预测,如何进一步预测2年?
我已经训练了LSTM模型,并想在未来再预测2年吗?火车数据是一组5年的每周销售数据。
df=pd.read_csv('data.csv')
subplotindex=0
numrows=4
numcols=2
fig,ax = plt.subplots(numrows,numcols,figsize=(18,15))
plt.subplots_adjust(wspace=0.1,hspace=0.3)
warnings.filterwarnings("ignore")
r=['product1','product2']
for x in r:
rowindex=math.floor(subplotindex/numcols)
colindex=subplotindex-(rowindex*numcols)
X=df[x].values
scaler = MinMaxScaler(feature_range = (0,1))
X=scaler.fit_transform(X.reshape(-1,1))
X_train,y_train=split_sequence(X[0:size],n_steps)
X_test,y_test=split_sequence(X[size:len(df)],n_steps)
X_train = X_train.reshape((X_train.shape[0],X_train.shape[1],n_features))
model = Sequential()
model.add(Bidirectional(LSTM(52,activation='relu'),input_shape=(n_steps,n_features)))
model.add(Dense(1))
model.compile(optimizer='adam',loss='mse')
model.fit(X_train,y_train,epochs=400,verbose=0)
X_test = X_test.reshape((len(X_test),n_steps,n_features))
predictions = model.predict(X_test,verbose=0)
y_test=scaler.inverse_transform(y_test)
predictions = scaler.inverse_transform(predictions)
error = mean_squared_error(y_test,predictions)
perror = mean_absolute_percentage_error(y_test,predictions)
resultsLongtermdf.loc['Bidirectional LSTM MSE',x]=error
resultsLongtermdf.loc['Bidirectional LSTM MAPE',x]=perror
ax[rowindex,colindex].set_title(x+' (MSE=' + str(round(error,2))+',MAPE='+ str(round(perror,2)) +'%)')
ax[rowindex,colindex].legend(['Real','Predicted'],loc='upper left')
ax[rowindex,colindex].plot(y_test)
ax[rowindex,colindex].plot(predictions,color='red')
subplotindex=subplotindex+1
plt.show()
那我该如何将预测设置为未来部分?
请您也向我解释为什么inverse_transform是什么?
y_test=scaler.inverse_transform(y_test)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。