python 二次平滑_时序分析 指数平滑
該帖主要介紹了一次指數平滑法、二次指數平滑法以及三次指數平滑法。
1 簡介
指數平滑法是對單變量數據進行時間序列預測的一種方法,它可以推廣到具有系統趨勢或季節成分的數據。
建模類似Box-Jenkins ARIMA的建模方式,但其預測是最近的過去觀測或滯后的加權線性和。
指數平滑預測法與用過去觀測值的加權和進行預測相似,但是模型的過去觀測值的權重是指數遞減的。
具體地說,過去的觀測結果是按幾何遞減比例加權的:
Forecasts produced using exponential smoothing methods are weighted averages of past observations, with the weights decaying exponentially as the observations get older. In other words, the more recent the observation the higher the associated weight. — Page 171, Forecasting: principles and practice, 2013.
指數平滑和ARIMA有時被統稱為ETS模型,指的是對誤差、趨勢和季節性的建模。
指數平滑預測法主要有三種:
- 沒有系統結構的簡單指數平滑,又叫一次指數平滑,這里結構是指趨勢和季節
- 有明確趨勢的叫二次指數平滑
- 有趨勢和季節性的叫三次指數平滑
2 一次指數平滑
一次指數平滑(single exponential smoothing, SES),是一種對沒有趨勢或季節性的單變量時間序列的預測方法。
它需要一個參數,稱為?,也稱為平滑因子或平滑系數。
這個參數控制前面歷史觀測值的權重指數遞減速度。常被設置為0到1之間的值。大的值意味著模型更關注最近的觀測值,小的值意味著預測時更關注歷史觀測值。
A value close to 1 indicates fast learning (that is, only the most recent values influence the forecasts), whereas a value close to 0 indicates slow learning (past observations have a large influence on forecasts).
超參:
Alpha:smoothing factor for the level.
python實現
from statsmodels.tsa.holtwinters import SimpleExpSmoothing# prepare data
data = ...
# create class
model = SimpleExpSmoothing(data)
# fit model
model_fit = model.fit(...)
# make prediction
yhat = model_fit.predict(...)
3 二次指數平滑
雙指數平滑( double exponential smoothing)是指數平滑的擴展,它增加了對單變量時間序列趨勢的支持。
參數除了用于控制水平的平滑因子 alpha,還增加了用于控制趨勢變化影響的衰減平滑因子 beta 。
該方法支持不同變化方式的趨勢:加法和乘法,取決于趨勢是線性還是指數的。
加性趨勢(additive trend):具有線性趨勢的雙指數平滑
乘性趨勢(multiplicative trend):具有指數趨勢的雙指數平滑
二次指數平滑通常稱為 Holt 線性趨勢模型,以開發者 Charles Holt 命名。
對于較大時間步長的預測,趨勢可能會不符合實際。因此,隨著時間的推移,可能需要抑制這種趨勢。
抑制(dampening)意味著隨著未來時間的推移將減少趨勢的大小直至成為一條直線(沒有趨勢)。
與趨勢建模一樣,可用相同原則來抑制趨勢,尤其是線性的加性和指數的乘性的抑制效果。抑制系數 Phi 用于控制抑制的速度。
加性抑制(additive dampening):抑制線性趨勢
乘性抑制(multiplicative dampening):抑制指數趨勢
超參:
Alpha:smoothing factor for the level.
Beta: Smoothing factor for the trend.
Trend Type: Additive or multiplicative.
Dampen Type: Additive or multiplicative.
Phi: Damping coefficient.
python實現
from statsmodels.tsa.holtwinters import ExponentialSmoothing# prepare data
data = ...
# create class
model = ExponentialSmoothing(data, ...)
# fit model
model_fit = model.fit(...)
# make prediction
yhat = model_fit.predict(...)
4 三次指數平滑
三次指數平滑是指數平滑的擴展,它為單變量時間序列增加了對季節性的支持。
這種方法有時被稱為 Holt-Winters 指數平滑法,以該方法的兩位貢獻者 Charles Holt and Peter Winters 的名字命名。
除了alpha和beta平滑因子外,還添加了一個新的參數 gamma,該參數控制對季節成分的影響。
與趨勢一樣,季節性也有加性(線性)或乘性(指數)過程。
加法季節性(additive seasonality):具有線性季節性的三次指數平滑。
乘法季節性(multiplicative seasonality):具有指數季節性的三次指數平滑。
三次指數平滑是指數平滑最先進的變體,通過參數配置,還可以建立雙指數平滑模型和單指數平滑模型。
Being an adaptive method, Holt-Winter’s exponential smoothing allows the level, trend and seasonality patterns to change over time.
為了確保正確地對季節性建模,必須指定季節性的時間步長。若該時序是月度數據,而季節周期每年重復,那么周期=12。
超參:
Alpha:smoothing factor for the level.
Beta: Smoothing factor for the trend.
Trend Type: Additive or multiplicative.
Dampen Type: Additive or multiplicative.
Phi: Damping coefficient.
Seasonality Type: Additive or multiplicative.
Period: Time steps in seasonal period.
python實現
同二次指數平滑
5 參數選取
以上所有超參都可手動設置,這種方法適合專家或初學者。
正常會用數值優化的方法通過最小誤差來找平滑參數。
a more robust and objective way to obtain values for the unknown parameters included in any exponential smoothing method is to estimate them from the observed data. the unknown parameters and the initial values for any exponential smoothing method can be estimated by minimizing the SSE [sum of the squared errors].
總結
以上是生活随笔為你收集整理的python 二次平滑_时序分析 指数平滑的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux下源码安装Kong网关
- 下一篇: 创建图库