Ape Creation Call for Papers|Secondary Exponential Smoothing and Triple Exponential Smoothing of Time Series Analysis Algorithms + Python code implementation

Table of contents

foreword

Second exponential smoothing method (Holt's linear trend method)

1. Definition

2. Formula

Quadratic exponential smoothing value:

Quadratic exponential smoothing mathematical model:

 3. Case realization

Triple Exponential Smoothing (Holt-Winters' seasonal method)

1. Definition

2. Formula

 3. Case realization

Selection of Weighting Coefficient a

Pay attention, prevent getting lost, if there are any mistakes, please leave a message for advice, thank you very much

see



foreword

It has been a long time since I updated the time series analysis algorithm. Today, I will complete the smoothing method, a commonly used and broad time series algorithm. The end of this article means that the entire traditional time series prediction algorithm is finished. The content of the article is immediately following the previous article:

A quick study - detailed explanation of exponential smoothing method of time series analysis algorithm + Python code implementation - Fanstuck's Blog - CSDN Blog - Exponential Smoothing Python

 The next article will explain all the models and algorithms for univariate time series forecasting in detail. This series will continue to write about the popular LSTM short-term time series prediction and more advanced and convenient time series prediction algorithms.

I hope that readers can make mistakes or opinions in the comment area after reading, and bloggers will maintain the blog for a long time and update it in time.


Second exponential smoothing method (Holt's linear trend method)

From the simple moving average method we learned before and the quadratic moving average method (also known as the trend moving average method) derived on this basis, the relationship between the first exponential smoothing method and the second exponential smoothing method is similar. It can be said that the principle is the same.

1. Definition

On the basis of an exponential smoothing method, a trend move is made. When the changes of the time series show a linear trend, there will still be obvious lag deviations for forecasting by the one-time exponential smoothing method. The correction method is also to perform second exponential smoothing on the basis of one exponential smoothing, using the law of lag deviation to find out the development direction and development trend of the curve, and then establish a linear trend prediction model, so it is called the second exponential smoothing method.

2. Formula

Let's look at the formula for exponential smoothing again:

Let the time series be y_{1},y_{2},...,y_{t}...,\alphathe weighted coefficient, 0<\alpha <1, and the formula for an exponential smoothing is:

 y^{'}_{t+1}is the predicted value at time t+1, that is, the smoothed value at time t S_{t}, and y_{t}is the actual value at time t; y^{'}_{t}is tthe predicted value at time, which is the smoothed value at the previous time S_{t-1}. Obviously, this formula is improved from the moving average formula .

We do the same with the quadratic moving average method.

Quadratic exponential smoothing value :

 formula:

  • S^{(2)}_t: the quadratic exponential smoothing value of the t-th period
  • S^{(1)}_t: An exponential smoothing value for the t-th period
  • S^{(2)}_{t-1}: The second exponential smoothing value of the t-1th period
  • \alpha: Weighting coefficient (smoothing coefficient)

It is easy to see that the second exponential smoothing method is a method of exponentially smoothing one exponentially smoothed value again. Therefore, it is necessary to use an exponential smoothing method before calculating it.

Quadratic exponential smoothing mathematical model:

 3. Case realization

Here we no longer use case 1 of the last chemical experiment, but a different case:

Taking my country's total power generation data from 1965 to 1985 as an example, try the quadratic exponential smoothing method to predict the total power generation in 1986 and 1987:

 Then we just need to read in the data and introduce the SES one-time smoothing exponential method we wrote before:

import pandas as pd
import numpy as np
import Ipynb_importer
import SES
df=pd.read_excel('try_test2.xlsx')

 First, we get a smooth value, and the smooth coefficient is still 0.3:

df=pd.read_excel('try_test2.xlsx')
x=df['t']
y=df['发电总量y']
y_1=SES(y,1,0.3)
y_1

 

 To obtain the secondary smoothed value, we only need to substitute the primary smoothed value again to get:

y_2=SES(y_2,1,0.3)
y_2

 

 Then if we want to predict the value of t at time 21, we need to get the values ​​of the two parameters a and b:

#我们需要传入一次平滑预测值和二次平滑预测值,以及t值、平滑系数a和给予的T
def SES_quadratic(y_1,y_2,s,t,T):
    a=2*y_1[t-1]-y_2[t-1]
    b=(s/(1-s))*(y_1[t-1]-y_2[t-1])
    y=a+b*T
    return y
SES_quadratic(y_1,y_2,0.3,21,1)

In this way, we get the predicted value when t is 22:

Triple Exponential Smoothing (Holt-Winters' seasonal method)

1. Definition

The first-order exponential smoothing method is for the series without trend and seasonality, the second-order exponential smoothing method is for the time series with trend but no seasonal characteristics, and the third-order exponential smoothing method can predict the time series with trend and seasonality. The term "Holt-Winter" refers to triple exponential smoothing. The method is divided into a prediction equation and three smoothing equations, one is the level, the other is the trend, and the other is the seasonal component. The smoothing parameter sum is used to represent the seasonal cycle, such as the number of seasons in a year, the number of seasons, the number of months quantity.

When we talk about time series data directly, time series has the following four time series characteristics:

  • Long-term trend (Trend)
  • Seasonal Change (Season)
  • Cyclic
  • Irregular fluctuations (Irregular)

The seasonal variation is also the smoothing represented by the triple exponential smoothing method. The following URL is the full description of the seasonal forecasting algorithm:

7.3 Holt-Winters’ seasonal method | Forecasting: Principles and Practice (2nd ed)

I also said earlier in the first article:

There are usually two combinations of the four influencing factors:

One is the additive model: Y=T+S+C+I, which believes that the development trend of the data is the result of the superposition of four influencing factors

One is the multiplication model: Y=T*S*C*I, which believes that the development trend of the data is the result of the mutual integration of four factors

There are two variants of this method, which differ according to the nature of the seasonal components. The additive model is preferred when the seasonal variation is approximately constant across the series, and the multiplicative model is preferred when the seasonal variation is proportional to the series level. Using the additive method, the seasonal component is expressed as an absolute value in the scale of the observed series, and in the horizontal equation, the series is seasonally adjusted by subtracting the seasonal component. Within each year, the sum of the seasonal components will be close to zero. Using the multiplicative method, the seasonal component is expressed in relative terms (percentage), and the series is seasonally adjusted by dividing by the seasonal component. Within each year, the seasonal components total about m.

Then the Holt-Winters additive model is:

where k is the integer part of (h−1)/m, which ensures that the estimates of the seasonal index used for forecasting are from the last year of the sample. y_{t}-s_{t-m}The horizontal equation shows the weighted average between the seasonally adjusted observations ( ), and the non-seasonal forecast ( \imath _{t-1}+b_{t-1}) for time t, and the trend equation is the same as Holt's linear approach. The seasonal equation shows y_{t}-\imath _{t-1}-b_{t-1}the weighted average between the current seasonal index ( ), and the seasonal index for the same season last year (i.e. m time periods ago).

The equation for the seasonal component is usually expressed as:

 If we substitute ℓ from the above smoothing equation for the levels in component form, we get

 Correspondingly, the multiplication model is:

2. Formula

We don't need to re-understand the triple exponential smoothing method again. The third smoothing method is nothing more than smoothing once again on the basis of the quadratic smoothing method. Then the derivation formula is even simpler:

The formula for its cubic smoothing value is:

where S^{(3)}_{t}is the triple exponential smoothing value.

 The prediction model of the triple exponential smoothing method is:

 3. Case realization

Our case is still the same as the case of the quadratic exponential smoothing method, and everyone in the province will understand other case scenarios.

We can first plot the points to see if the data is more suitable for the triple exponential smoothing method:

import matplotlib.pyplot as plt
df=pd.read_excel('try_test2.xlsx')
x=df['t']
y=df['发电总量y']
plot1 = plt.plot(x, y, '*', label='origin data')
plt.title('metric_polyfit')
plt.show()

 Then we find that the data of this case is linearly increasing, then we have to change the case. It is best to use the case of the last chemical reaction here.

Take the data of measured product concentration y (%) and time t (min) in a chemical reaction as an example:

 

Through the actual data series showing a nonlinear increasing trend, the triple exponential smoothing prediction method is used.

Determine the initial value and weight factor (smoothing factor) a for exponential smoothing . Set the initial value of the first, second and third exponential smoothing as the average value of the earliest three data . which is:

S^{(1)}_{0}=S^{(2)}_{0}=S^{(3)}_{0}=\frac{y_1+y_2+y_3}{3}=\frac{4+6.4+8}{3}=6.13

Take \alphait as 0.3, then we will S^{(1)}_{16},S^{(2)}_{16},S^{(3)}_{16}find out first:

y_1=SES(y,3,0.3)
y_2=SES(y_1,3,0.3)
y_3=SES(y_2,3,0.3)

Then we can use python to write the code:

#我们需要传入一次平滑预测值、二次平滑预测值和三次平滑预测值,以及t值、平滑系数a和给予的T
def SES_triple(y_1,y_2,y_3,s,t,T):
    t=t-1
    a=y_1[t]*3-y_2[t]*3+y_3[t]
    b=(s/(2*((1-s)**2)))*((6-5*s)*y_1[t]-2*(5-4*s)*y_2[t]+(4-3*s)*y_3[t])
    c=((s**2)/(2*((1-s)**2)))*(y_1[t]-2*y_2[t]+y_3[t])
    y=a+b*T+c*T**2
    return y
SES_triple(y_1,y_2,y_3,0.3,16,1)

 

Selection of Weighting Coefficient a

In exponential smoothing, the key to successful prediction is the choice of a. The size of a specifies the proportion of the new data and the original forecast in the new forecast. The larger the value of a, the larger the proportion of new data, and the smaller the proportion of the original forecast, and vice versa.

        Theorists generally believe that the following methods are available:

        empirical judgment. This method mainly relies on the development trend of the time series and the experience of the forecaster to make judgments.

1. When the time series shows a relatively stable horizontal trend, a smaller α value should be selected, generally between 0.05 and 0.20;

2. When the time series fluctuates, but the long-term trend does not change much, a slightly larger α value can be selected, usually between 0.1 and 0.4;

3. When the time series fluctuates greatly, the long-term trend changes greatly, and shows an obvious and rapid upward or downward trend, a larger α value should be selected, such as a value between 0.6 and 0.8, so as to make the prediction model more sensitive. Higher, can quickly keep up with changes in data;

4. When the time series data is a rising (or falling) development trend type, α should take a larger value, between 0.6 and 1.

        try algorithm. According to the specific time series situation, refer to the empirical judgment method to roughly determine the rated value range, and then take several α values ​​for trial calculation, compare the forecast standard errors under different α values, and select the α with the smallest forecast standard error.

        In practical applications, the forecaster should make qualitative judgments and calculate the forecast error based on the change rule of the forecast object, and should take into account that the forecast sensitivity and forecast accuracy are contradictory, and certain considerations must be given to the two, and a compromise α should be used. value.


Pay attention, prevent getting lost, if there are any mistakes, please leave a message for advice, thank you very much

That's all for this issue. I'm fanstuck. If you have any questions, feel free to leave a message to discuss. See you in the next issue.

see

Time Series Models (3

Exponential Smoothing (ES) - Idea Reply Blog - CSDN Blog - Exponential Smoothing

Guess you like

Origin blog.csdn.net/master_hunter/article/details/126598557