# Time Series Prediction以RNN(Simple RNN,LSTM,GRU)進行時間序列預測 ###### table of Contents [TOC] ## 問題解釋 ![](https://i.imgur.com/32PejGf.png) - 此次作業為 **深度學習導論** 第三次作業 - [**作業題目** ](http://www.elearn.ndhu.edu.tw/moodle/file.php/80281/Assingment_3.pdf) - [**data(需要登入東華e學苑)** ](http://www.elearn.ndhu.edu.tw/moodle/file.php/80281/A3_train.txt) ## 解決辦法 ```python= # build the LSTM RNN model = Sequential() model.add(LSTM(units = 32, input_shape = (1, time_series_len))) model.add(Dense(units = 1, activation = 'relu')) model.compile(loss = 'mean_squared_error', optimizer=Adam(decay=0.001), metrics=['mae','mse', 'acc']) ``` - 使用LSTM訓練 - 以 $[x_{1+i},x_{50+i}]$ 為一組訓練資料輸入,預測$x_{51+i}$ - 模型 ![](https://i.imgur.com/UzVCc9C.png) 以一層LSTM層連一層Dense層建構此次模型,共兩層。 - Dense激活函數為線性整流函數 **Relu** - 通過compile方法完成學習過程的配置。 - 損失函數是 **mean_squared_error** ,優化器是 **Adam**。 ## 結果 ![](https://i.imgur.com/t4MCXXy.png) ![](https://i.imgur.com/Jpiagis.png) ## 最後總結 - 此次作業相較於上次CNN,因為模型架構較簡單,訓練速度也比較快。 - 時間序列長度切愈長,訓練的資料量會愈少,目測資料50~80會有一個週期,於是選擇50,一部分也是因為50這數字可以被1000整除。