簡體   English   中英

為什么我的 Keras LSTM model 在時間序列預測上與 RandomForest 相比表現糟糕?

[英]Why does my Keras LSTM model perform horrible compared to RandomForest on timeseries forecasting?

我有一個 DataFrame 根據一些傳感器數據預測通過道路的車輛數量。

DataFrame 按照以下格式進行整形,並根據時間戳進行索引

         index           |    t   |   t - 1   |   t - 2 |  ....  |   t - 95 |  number of cars
2020-08-01 : 00:00:15        410        499         380     ...        20         240
2020-08-01 : 00:00:30        305        410         499     ...        45         244
2020-08-01 : 00:00:45        290        305         410     ...        50         188

數據具有以下形狀X_train.shape = (4210,97)

我做的是以下

train = df.loc['2020-08-01 : 00:00:15':'2020:09:12 23:45:00']
test = df.loc['2020-09-13 : 00:00:00':]
y_train = train['number of cars']
X_train = train.drop('y',axis=1)
sc = StandardScaler()
sc.fit(X_train)
X_train= sc.transform(X_train)

y_test = test['number of cars']
X_test = test.drop('y',axis=1)
X_test = sc.transform(X_test)


rf = RandomForest()
rf.fit(X_train,y_train)
preds = rf.predict(X_test)

print(r2_score(preds,y_test))
print(mean_squared_error(preds,y_test))

這使

'r2 : 0.89'
'mse : 60'
   

我想看看 LSTM model 是否可以做得更好

 X_train_lstm = X_train.values.reshape(X_train.shape[0],X_train.shape[1],1)
 X_test_lstm = X_train.values.reshape(X_train.shape[0],X_train.shape[1],1)

 model = Sequential()
 model.add(LSTM(units=64, return_sequences=False,activation='relu', input_shape (96, 1)))
 model.add(Dense(units=1))
 model.compile(loss='mean_squared_error', optimizer='adam')
 model.fit(X_train_lstm,y_train,batch_size=64,epochs=100)
 lstm_preds = model.predict(X_test_lstm)

 print(r2_score(lstm_preds,y_test))
 print(mean_squared_error(lstm_preds,y_test))

這使

 'r2 : -0.3'
 'mse : 2100040'

  print(lstm_preds)

  [38,38.12,38.1,38,38.2,....,38]

   

預測值基本上是相同的值,我在這里做錯了什么?

我認為主要問題是您的y_trainy_test沒有標准化。

此外,對於LSTM層,您不應更改激活。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM