快速探索
===
###### tags: `ML / 時間序列`
###### tags: `ML`, `時間序列`
<br>
[TOC]
<br>
## 簡介
### 時間序列預測帶來的價值
- [多元時間序列預測的時間模式注意](https://kknews.cc/code/y334n4j.html)
> 預測多變量時間序列數據,例如電力消耗預測,太陽能發電和複音鋼琴件,具有許多有價值的應用。
- 颱風路徑預測 -> 預防自然災害,減少損傷
<br>
### 時間序列預測 是一個挑戰
> [Time series forecasting is still a challenging task.](https://github.com/ITMO-NSS-team/fedot-examples/blob/main/notebooks/latest/3_intro_ts_forecasting.ipynb)
- ### 颱風路徑預測
- 大氣環流
- 太平洋高壓強弱
- 低壓環流變化
- [海洋 (颱風能量來源)](https://www.lis.ntu.edu.tw/~pnhsieh/courses/il/typhoon.pdf)
- 洋流
- [海水熱含量](https://www.facebook.com/twtybbs/posts/2518463304834328)

- 海水熱含量低:暖水層淺薄或海溫偏低,颱風一攪海溫就低於26度,能量供應中斷。
- 陸地地形
- ### 潮汐發電量預測
- 太陽 / 地球 / 月球相對位置
- [大潮/小潮](https://www.cwb.gov.tw/V8/C/K/Encyclopedia/sea/tidal_list.html)
<br>
<hr>
<br>
## 術語
### 單變量/多變量, 多變項/多變量?
- ### [醫學統計經常混淆的名詞~晨晰統計林星帆顧問整理](https://dasanlin888.pixnet.net/blog/post/34469753)
> 
- dependent variable 相依變項
- independent variable 自變項
- outcome variable 結果變項
> dependent variable 相依變項的另一種稱呼
- Covariate 共變量
- 自變項只有一個:
- simple regression 簡單迴歸 (應用統計)
- univariate regression 單變量迴歸 (醫學期刊、機器學習)
- 自變項有兩個以上(含):
- multiple regression 多元迴歸 (應用統計)
- multivariable regression 多變項迴歸 (醫學期刊)
- multivariate regression 多變量迴歸 (醫學期刊、機器學習)
- ### [多變項還是多變量?雙變項還是單變量?晨晰統計林星帆顧問整理](https://dasanlin888.pixnet.net/blog/post/468348827)
> 本篇文章旨在討論在醫學領域很常被誤用的統計名詞,有些名詞甚至錯誤(或說不精確)名詞的使用頻率還高過正確名詞。
>
> 不同尺度的解釋變項與結果變項的組合之下,所使用的統計方法都不同
> 
>
> 多變量分析是筆者認為在醫學領域論文最常被誤用的名詞。相較於單變量分析是指該統計分析只有一個結果變項,嚴謹定義之下的多變量分析是指『同時有 2 個或 2 個以上的結果變項』。

- ### [A Multivariate Time Series Guide to Forecasting and Modeling (with Python codes)](https://www.analyticsvidhya.com/blog/2018/09/multivariate-time-series-guide-forecasting-modeling-python-codes/)
<br>
### Time-Series Forecasting 時間序列預測
- [Multi-Step Multivariate Time-Series Forecasting using LSTM](https://pangkh98.medium.com/multi-step-multivariate-time-series-forecasting-using-lstm-92c6d22cd9c2)
根據過去的自變量X預測未來的應變量y
### Multivariate Forecasting 多元預測 (多變量預測)
- [Multi-Step Multivariate Time-Series Forecasting using LSTM](https://pangkh98.medium.com/multi-step-multivariate-time-series-forecasting-using-lstm-92c6d22cd9c2)
- 根據一個自變量X預測應變量y,為單元預測
- 根據多個自變量X預測應變量y,為多元預測
### Multi-step Forecasting 多步預測
- [Multi-Step Multivariate Time-Series Forecasting using LSTM](https://pangkh98.medium.com/multi-step-multivariate-time-series-forecasting-using-lstm-92c6d22cd9c2)
- 每次預測下一個時間步長,為單步預測
- 每次預測數個時間步長,為多步預測
### [自回歸預測法](https://wiki.mbalib.com/zh-tw/%E8%87%AA%E5%9B%9E%E5%BD%92%E9%A2%84%E6%B5%8B%E6%B3%95)
> 自回歸預測法是指利用預測目標的歷史時間數列在不同時期取值之間存在的依存關係(即自身相關),建立起回歸方程進行預測。具體說,就是用一個變數的時間數列作為因變數數列,用同一變數向過去推移若幹期的時間數列作自變數數列,分析一個因變數數列和另一個或多個自變數數列之間的相關關係,建立回歸方程進行預測。
- 自回歸預測法的優點是所需資料不多,可用自變數數列來進行預測。但是這種方法受到一定的限制,即必須具有自相關。
- 跟一般迴歸的差異

https://udn.com/news/story/120940/5747789

<br>
<hr>
<br>
## 資料
> 前往:[[HackMD] 時間序列資料集](/7h4bK5EqRvSANplJSoq2Mg)
> 前往:[[HackMD] 標記工具](/IqF7MscCQeOAfSPirRMrZw)
<br>
<hr>
<br>
## 解決工具
### 神經網路
- ### LSTM
- **[Time Series Prediction with LSTM Recurrent Neural Networks in Python with Keras](https://machinelearningmastery.com/time-series-prediction-lstm-recurrent-neural-networks-python-keras/)**
> #International Airline Passengers #國際航空旅客


- **[Multi-Step Multivariate Time-Series Forecasting using LSTM](https://pangkh98.medium.com/multi-step-multivariate-time-series-forecasting-using-lstm-92c6d22cd9c2)**
#tensorflow.keras
- **王柏鈞 專欄**
- [時間序列的AI介紹](https://bc165870081.medium.com/%E6%99%82%E9%96%93%E5%BA%8F%E5%88%97%E7%9A%84ai%E4%BB%8B%E7%B4%B9-ff250cfc2ff9) (王柏鈞)
- 介紹: 時間序列是什麼
- 時間序列長什麼樣子
- 有週期性
- 不必然有週期性
- [【技術筆記─ 時序資料的機器學習建模 Day3】](https://bc165870081.medium.com/x-day3-f7cc14371a0)
- 單變量時間序列模型
- 使用Vanilla LSTM, Stacked LSTM, Bidirectional LSTM, CNN+LSTM
- ### [Multi-Step Multivariate Time-Series Forecasting using LSTM](https://pangkh98.medium.com/multi-step-multivariate-time-series-forecasting-using-lstm-92c6d22cd9c2)
- ### [artificial-neural-networks.ipynb](https://github.com/gakhov/pycon-ua-2018/blob/master/artificial-neural-networks.ipynb)
- ### [tensorflow] Convolutional and Recurrent Neural Networks (CNNs and RNNs)
- [Time series forecasting](https://www.tensorflow.org/tutorials/structured_data/time_series)
- ### MLP
- [How to Develop Multilayer Perceptron Models for Time Series Forecasting](https://machinelearningmastery.com/how-to-develop-multilayer-perceptron-models-for-time-series-forecasting/)
<br>
### 單一啟發式演算法
- ### ExponentialSmoothing
> Exponential-Smoothing 是由兩個參數組成,分別是
> - alpha (平滑因子,類似權重)
> - 初始預測值
>
> 計算方式:
> $預測值_{t+1} = alpha \times 實際值_{t+0} + (1 - alpha) \times 預測值_{t+0}$
>
> 範例:
> 
- ### [【时间序列 - 02】ExponentialSmoothing - 指数平滑算法](https://blog.csdn.net/Houchaoqun_XMU/article/details/81462739)
- ### [指數平滑預測(exponential smoothing forecast)](http://blog.udn.com/anserelearning/132015279)

- ### [Exponential Smoothing for Time Series Forecasting](https://statisticsbyjim.com/time-series/exponential-smoothing-time-series-forecasting/)
- ### [Hands-On Guide to Time Series Analysis using Simple Exponential Smoothing in Python](https://analyticsindiamag.com/hands-on-guide-to-time-series-analysis-using-simple-exponential-smoothing-in-python/)
- ### [Forecasting with a Time Series Model using Python: Part Two](https://www.bounteous.com/insights/2020/09/15/forecasting-time-series-model-using-python-part-two/)
- ### SSA method
- [SSA (метод)](https://ru.wikipedia.org/wiki/SSA_(%D0%BC%D0%B5%D1%82%D0%BE%D0%B4))
> from [AutoML for time series: advanced approaches with FEDOT framework](https://towardsdatascience.com/automl-for-time-series-advanced-approaches-with-fedot-framework-4f9d8ea3382c)
- ### ARIMA
- [Time Series forecasting using Auto ARIMA in python](https://towardsdatascience.com/time-series-forecasting-using-auto-arima-in-python-bb83e49210cd)
- [使用Python和R中的Auto ARIMA構建高性能時間序列模型](https://www.twblogs.net/a/5cbf2439bd9eee3aed784eb0)
<br>
### 演算法單一工具
- AutoRegression
> 前往:[[HackMD] 模型演算法 / AutoRegression](/4pcoLxH7T3-2dETjrR8lhQ)
- statsmodels
> 前往:[[HackMD] 工具 / statsmodels](/1No11YLRSv2y1dy7ipO16w)
<br>
### 演算法整合工具
- FEDOT
> 前往:[[HackMD] 工具 / FEDOT](/m7pKYeUAQfW6g6wPbEzYUA)
<br>
### 公有雲平台
- Azure
> 前往:[[HackMD] 平台 / Azure](/SJanQhc_Rp2sCuXPNNF6sw)
<br>
### 更多
- ### [An overview of time series forecasting models](https://towardsdatascience.com/an-overview-of-time-series-forecasting-models-a2fa7a358fcb)
- **Time series forecasting models**
1. Naïve, SNaïve
2. Seasonal decomposition (+ any model)
3. Exponential smoothing
4. ARIMA, SARIMA
5. GARCH
6. Dynamic linear models
7. TBATS
8. Prophet
9. NNETAR
10. [LSTM](https://github.com/davide-burba/forecasting_models/blob/master/python_models.ipynb)
- 範例程式碼 :+1: :100:
https://github.com/davide-burba/forecasting_models/blob/master/python_models.ipynb
- ### [Forecasting complex seasonal timeseries](https://www.kaggle.com/c/forecasting-complex-seasonal-timeseries/overview)
- [Intro do timeseries forecasting with python](https://machinelearningmastery.com/introduction-to-time-series-forecasting-with-python/)
- [An Introduction to Time Series Forecasting with Python](https://www.researchgate.net/publication/324889271_An_Introduction_to_Time_Series_Forecasting_with_Python) (PDF)
- ### [7 methods to perform Time Series forecasting (with Python codes)](https://www.analyticsvidhya.com/blog/2018/02/time-series-forecasting-methods/)
- Method 1 – Start with a Naive Approach
- Method 2 – Simple average
- Method 3 – Moving average
- Method 4 – Single Exponential smoothing
- Method 5 – Holt’s linear trend method
- Method 6 – Holt’s Winter seasonal method
- Method 7 – ARIMA
<br>
<hr>
<br>
## 衡量指標
### R^2^
- [[Hackmd] 迴歸 Regression / R2](https://hackmd.io/SAfD0J0YQr68ojV5yDdtoQ#R2)

- ### R^2^:殘差值的評估
- 殘差趨近於 0, R^2^ 則趨近於 1
- baseline: 拿平均值當作基本標準
- R^2^ 小於 0, 表示模型爛掉,比平均值預測還差
- TheCoecient of Determination(R^2^)

### The MeanForecastError (MFE)

### The MeanSquaredError (MSE)

### The Normalized MeanSquaredError (NMSE)

### Theil'sU

A good forecast has the U close to zero
<br>
<hr>
<br>
## 探索資料
- [Time Series Analysis - 時間序列模型基本概念:AR, MA, ARMA, ARIMA 模型](https://mropengate.blogspot.com/2015/11/time-series-analysis-ar-ma-arma-arima.html)
- [時間序列的AI介紹](https://bc165870081.medium.com/ff250cfc2ff9)
- Stride 步伐
- window-size 視窗大小
- [原文連結](https://machinelearningmastery.com/time-series-prediction-lstm-recurrent-neural-networks-python-keras/)
- Model-1: Zero-Rule model
- Model-2: LSTM Model (長短期記憶模型)
- [7 libraries that help in time-series problems](https://towardsdatascience.com/7-libraries-that-help-in-time-series-problems-d59473e48ddd)
- [5 Unexplored Python Libraries for Time Series Analysis](https://towardsdatascience.com/5-unexplored-python-libraries-for-time-series-analysis-e9375962fbb2)
- [時間序列資料庫Timescale推出新雲端服務,簡化使用且提供高可擴展性](https://www.ithome.com.tw/news/147147)
- [Day 24:銷售量預測(2) -- 『時間序列分析』技巧篇](https://ithelp.ithome.com.tw/articles/10195635?sc=pt)
<br>
<hr>
<br>
## 參考資料
- [[Azure] 使用 Python 設定 AutoML 來訓練時間序列預測模型](https://docs.microsoft.com/zh-tw/azure/machine-learning/how-to-auto-train-forecast)
- [[Kaggle][資料分析&機器學習] 第4.2講 : Kaggle競賽-共享單車需求預測(前17%排名)](https://medium.com/jameslearningnote/505ed7100825)
- [TimeSeries Analysis 📈A Complete Guide 📚](https://www.kaggle.com/andreshg/timeseries-analysis-a-complete-guide)
- [[LSTM] Time Series Prediction with LSTM Recurrent Neural Networks in Python with Keras](https://machinelearningmastery.com/time-series-prediction-lstm-recurrent-neural-networks-python-keras/)
- [[LSTM][MLP] 中低溫餘熱及壓差發電系統技術開發與應用計畫](https://km.twenergy.org.tw/KnowledgeFree/knowledge_more?id=8344)