<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 用 Python 編寫 SARIMA 時間序列預測 > 原文: [https://machinelearningmastery.com/sarima-for-time-series-forecasting-in-python/](https://machinelearningmastery.com/sarima-for-time-series-forecasting-in-python/) 自回歸綜合移動平均線(ARIMA)是用于單變量時間序列數據預測的最廣泛使用的預測方法之一。 盡管該方法可以處理具有趨勢的數據,但它不支持具有季節性組件的時間序列。 支持對該系列季節性組成部分進行直接建模的 ARIMA 擴展稱為 SARIMA。 在本教程中,您將發現季節性自回歸集成移動平均線(SARIMA)時間序列預測方法,其中包含趨勢和季節性的單變量數據。 完成本教程后,您將了解: * ARIMA 在季節性數據方面的局限性。 * ARIMA 的 SARIMA 擴展,明確地模擬單變量數據中的季節性元素。 * 如何使用 Statsmodels 庫在 Python 中實現 SARIMA 方法。 讓我們開始吧。 * **更新 Nov / 2018** :有關使用和網格搜索 SARIMA 超參數的幫助,請參閱此帖子: * [如何在 Python 中搜索用于時間序列預測的 SARIMA 模型超參數](https://machinelearningmastery.com/how-to-grid-search-sarima-model-hyperparameters-for-time-series-forecasting-in-python/) ![A Gentle Introduction to SARIMA for Time Series Forecasting in Python](https://img.kancloud.cn/c3/93/c393d54284ce840dd0ab2d87fb30aa02_640x360.jpg) 用于 Python 中時間序列預測的 SARIMA 的溫和介紹 [Mario Micklisch](https://www.flickr.com/photos/fvfavo/15438357162/) 的照片,保留一些權利。 ## 教程概述 本教程分為四個部分;他們是: 1. ARIMA 有什么不對 2. 什么是 SARIMA? 3. 如何配置 SARIMA 4. 如何在 Python 中使用 SARIMA ## ARIMA 有什么不對 自回歸綜合移動平均線(ARIMA)是單變量時間序列數據的預測方法。 顧名思義,它支持自回歸和移動平均元素。集成元素指的是差分,允許該方法支持具有趨勢的時間序列數據。 ARIMA 的一個問題是它不支持季節性數據。這是一個重復循環的時間序列。 ARIMA 預計數據不是季節性的,或者季節性成分被刪除,例如通過季節性差異等方法進行季節性調整。 有關 ARIMA 的更多信息,請參閱帖子: * [如何使用 Python 創建用于時間序列預測的 ARIMA 模型](https://machinelearningmastery.com/arima-for-time-series-forecasting-with-python/) 另一種方法是使用 SARIMA。 ## 什么是 SARIMA? 季節性自回歸整合移動平均線,SARIMA 或季節性 ARIMA,是 ARIMA 的擴展,明確支持具有季節性成分的單變量時間序列數據。 它增加了三個新的超參數來指定系列季節性成分的自回歸(AR),差分(I)和移動平均(MA),以及季節性周期的附加參數。 > 通過在 ARIMA 中包含額外的季節性術語來形成季節性 ARIMA 模型[...]模型的季節性部分由與模型的非季節性組成非常相似的術語組成,但它們涉及季節性時段的后移。 - 第 242 頁,[預測:原則和實踐](https://amzn.to/2xlJsfV),2013。 ## 如何配置 SARIMA 配置 SARIMA 需要為系列的趨勢和季節性元素選擇超參數。 ### 趨勢元素 有三個趨勢元素需要配置。 它們與 ARIMA 模型相同;特別: * **p** :趨勢自動回歸順序。 * **d** :趨勢差異順序。 * **q** :趨勢均線。 ### 季節性元素 有四個不屬于 ARIMA 的季節性元素必須配置;他們是: * **P** :季節性自回歸順序。 * **D** :季節性差異順序。 * **Q** :季節性移動平均線。 * **m** :單個季節性時段的時間步數。 同時,SARIMA 模型的表示法指定為: ```py SARIMA(p,d,q)(P,D,Q)m ``` 指定模型的特定選擇超參數的位置;例如: ```py SARIMA(3,1,0)(1,1,0)12 ``` 重要的是, _m_ 參數影響 _P_ , _D_ 和 _Q_ 參數。例如,月度數據的 m 為 12 表示每年的季節性周期。 _P_ = 1 將利用模型中的第一個季節性偏移觀察,例如 t-(m * 1)或 t-12。 _P_ = 2,將使用最后兩個季節性偏移的觀測值 t-(m * 1),t-(m * 2)。 類似地,1 的 _D_ 將計算一階季節差異,并且 _Q_ = 1 將使用模型中的一階誤差(例如,移動平均值)。 > 季節性 ARIMA 模型使用等于季節數的滯后差異來消除加性季節效應。與滯后 1 差分去除趨勢一樣,滯后差分引入移動平均項。季節性 ARIMA 模型包括滯后 s 處的自回歸和移動平均項。 - 第 142 頁,[入門時間序列與 R](https://amzn.to/2smB9LR) ,2009 年。 可以通過仔細分析 ACF 和 PACF 圖來選擇趨勢元素,其中查看最近時間步長(例如,1,2,3)的相關性。 類似地,可以通過查看季節性滯后時間步長的相關性來分析 ACF 和 PACF 圖以指定季節模型的值。 有關解釋 ACF / PACF 圖的更多信息,請參閱帖子: * [自相關和部分自相關的溫和介紹](https://machinelearningmastery.com/gentle-introduction-autocorrelation-partial-autocorrelation/) > 季節性 ARIMA 模型可能具有大量參數和術語組合。因此,在擬合數據時嘗試各種模型并使用適當的標準選擇最佳擬合模型是合適的... - 第 143-144 頁,[介紹時間序列與 R](https://amzn.to/2smB9LR) ,2009 年。 或者,可以在趨勢和季節性超參數中使用網格搜索。 有關網格搜索 ARIMA 參數的更多信息,請參閱帖子: * [如何使用 Python 網格搜索 ARIMA 模型超參數](https://machinelearningmastery.com/grid-search-arima-hyperparameters-with-python/) ## 如何在 Python 中使用 SARIMA 通過 [Statsmodels 庫](http://www.statsmodels.org/dev/statespace.html)在 Python 中支持 S??ARIMA 時間序列預測方法。 要使用 SARIMA,有三個步驟,它們是: 1. 定義模型。 2. 適合定義的模型。 3. 使用擬合模型進行預測。 讓我們依次看一下每一步。 ### 1.定義模型 可以通過提供訓練數據和大量模型配置參數來創建 SARIMAX 類的實例。 ```py # specify training data data = ... # define model model = SARIMAX(data, ...) ``` 該實現稱為 SARIMAX 而不是 SARIMA,因為方法名稱中的“X”意味著該實現還支持外生變量。 這些是并行時間序列變量,它們不是通過 AR,I 或 MA 過程直接建模,而是作為模型的加權輸入提供。 外源變量是可選的,可以通過“ _exog_ ”參數指定。 ```py # specify training data data = ... # specify additional data other_data = ... # define model model = SARIMAX(data, exog=other_data, ...) ``` 趨勢和季節性超參數分別指定為“_ 順序 _”和“ _seasonal_order_ ”參數的 3 和 4 元素元組。 必須指定這些元素。 ```py # specify training data data = ... # define model configuration my_order = (1, 1, 1) my_seasonal_order = (1, 1, 1, 12) # define model model = SARIMAX(data, order=my_order, seasonal_order=my_seasonal_order, ...) ``` 這些是主要的配置元素。 您可能需要配置其他微調參數。在完整的 API 中了解更多信息: * [statsmodels.tsa.statespace.sarimax.SARIMAX API](http://www.statsmodels.org/dev/generated/statsmodels.tsa.statespace.sarimax.SARIMAX.html) ### 2.適合模型 創建模型后,它可以適合訓練數據。 通過調用 [fit()函數](http://www.statsmodels.org/dev/generated/statsmodels.tsa.statespace.sarimax.SARIMAX.fit.html)來擬合模型。 擬合模型返回 _SARIMAXResults_ 類的實例。此對象包含擬合的詳細信息,例如數據和系數,以及可用于使用模型的函數。 ```py # specify training data data = ... # define model model = SARIMAX(data, order=..., seasonal_order=...) # fit model model_fit = model.fit() ``` 可以配置擬合過程的許多元素,一旦您熟悉實現,就值得閱讀 API 以查看這些選項。 * [statsmodels.tsa.statespace.sarimax.SARIMAX.fit API](http://www.statsmodels.org/dev/generated/statsmodels.tsa.statespace.sarimax.SARIMAX.fit.html) ### 3.進行預測 適合后,該模型可用于進行預測。 可以通過在調用 fit 返回的 _SARIMAXResults_ 對象上調用 _forecast()_ 或 _predict()_ 函數來進行預測。 [forecast()函數](http://www.statsmodels.org/dev/generated/statsmodels.tsa.statespace.sarimax.SARIMAXResults.forecast.html)采用單個參數指定要預測的采樣時間步數,或者如果未提供參數則采用一步預測。 ```py # specify training data data = ... # define model model = SARIMAX(data, order=..., seasonal_order=...) # fit model model_fit = model.fit() # one step forecast yhat = model_fit.forecast() ``` _predict()_ 函數需要指定開始和結束日期或索引。 此外,如果在定義模型時提供了外生變量,則它們也必須在 _predict()_ 函數的預測期內提供。 ```py # specify training data data = ... # define model model = SARIMAX(data, order=..., seasonal_order=...) # fit model model_fit = model.fit() # one step forecast yhat = model_fit.predict(start=len(data), end=len(data)) ``` ## 進一步閱讀 如果您希望深入了解,本節將提供有關該主題的更多資源。 ### 帖子 * [如何在 Python 中搜索用于時間序列預測的 SARIMA 模型超參數](https://machinelearningmastery.com/how-to-grid-search-sarima-model-hyperparameters-for-time-series-forecasting-in-python/) * [如何使用 Python 創建用于時間序列預測的 ARIMA 模型](https://machinelearningmastery.com/arima-for-time-series-forecasting-with-python/) * [如何使用 Python 網格搜索 ARIMA 模型超參數](https://machinelearningmastery.com/grid-search-arima-hyperparameters-with-python/) * [自相關和部分自相關的溫和介紹](https://machinelearningmastery.com/gentle-introduction-autocorrelation-partial-autocorrelation/) ### 圖書 * 第 8 章 ARIMA 模型,[預測:原則和實踐](https://amzn.to/2xlJsfV),2013。 * 第 7 章,非平穩模型, [R](https://amzn.to/2smB9LR) 的入門時間序列,2009。 ### API * [Statsmodels 狀態空間方法的時間序列分析](http://www.statsmodels.org/dev/statespace.html) * [statsmodels.tsa.statespace.sarimax.SARIMAX API](http://www.statsmodels.org/dev/generated/statsmodels.tsa.statespace.sarimax.SARIMAX.html) * [statsmodels.tsa.statespace.sarimax.SARIMAXResults API](http://www.statsmodels.org/dev/generated/statsmodels.tsa.statespace.sarimax.SARIMAXResults.html) * [Statsmodels SARIMAX 筆記本](http://www.statsmodels.org/dev/examples/notebooks/generated/statespace_sarimax_stata.html) ### 用品 * [維基百科上的自回歸綜合移動平均線](https://en.wikipedia.org/wiki/Autoregressive_integrated_moving_average) ## 摘要 在本教程中,您發現了季節性自回歸集成移動平均線(SARIMA),用于包含趨勢和季節性的單變量數據進行時間序列預測。 具體來說,你學到了: * ARIMA 在季節性數據方面的局限性。 * ARIMA 的 SARIMA 擴展,明確地模擬單變量數據中的季節性元素。 * 如何使用 Statsmodels 庫在 Python 中實現 SARIMA 方法。 你有任何問題嗎? 在下面的評論中提出您的問題,我會盡力回答。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看