1. Concept
Time Series
Time series refers to a sequence in which the values of the same statistical indicator are arranged in the order of their occurrence time (a sequence of observation values at uniform time intervals).
The main purpose of time series analysis is to predict the future based on existing historical data.
Time series analysis mainly includes: trend analysis, sequence decomposition, and sequence prediction.
Time-Series Decomposition
Time series are classified according to seasonality and are divided into seasonal time series and non-seasonal time series.
Components of time series:
-
Long-term trend T: The general trend of changes formed by a phenomenon affected by some fundamental factors over a long period of time
-
Seasonal changes S: regular cyclical changes in phenomena that occur with seasonal changes within a year
-
Cyclic trend C: The phenomenon exhibits regular changes in the form of waves in a period of several years.
-
Irregular changes I: It is an irregular change, including strict random changes and irregular sudden changes with great impact.
2. Non-seasonal time series
Moving average (MA, Moving Average)
Moving average is a simple smoothing technique that expresses the long-term changes and development trends of indicators by taking the mean of a certain number of items on a time series one by one.
1. Simple Moving Average (SMA)
The simple moving average is a simple arithmetic average of the first n values in the time series.
SMAn = ( x1 + x2 + …… + xn)/ n
2. Weighted Moving Average (WMA)
Weighted moving average, based on the simple moving average, assigns corresponding weights to each value of the previous n periods in the time series, that is, the result of the weighted average
The basic idea: improve recent data and weaken the impact of long-term data on the current forecast value, so that the forecast value is closer to the recent trend.
WMAn = w1x1 + w2x2 + …… + wnxn
3. Decomposition of non-seasonal time series
Decompose the non-seasonal time series into two parts: trend and irregular fluctuation.
#Import data and draw graphics to get the following graphics
3. Seasonal time series
In a time series, if similarities appear after n time intervals, the series has seasonal characteristics with a period of n.
Decomposition of seasonal time series
Decompose the seasonal time series into three parts: trend, periodicity and irregular fluctuation.
Tips: The time column needs to be converted into an index column to facilitate calculations
4. Sequence prediction
1. Concept
Forecast
Preliminary estimation and speculation of things that have not yet happened or are unclear at present is to discuss and study the results of things that will happen at the present time. Simply put, it refers to predicting unknown events from known events.
Time Series Forecasting
By analyzing the time series, we can make analogies or extensions based on the development process, direction and trend reflected in the time series, so as to predict the level that may be reached in the next period of time or in several subsequent periods of time.
Stationary Time Series
Stationary time series, whose statistical characteristics do not change with time, generally use mean, variance or covariance as statistical characteristics.
Difference (Integrated)
Commonly used time series forecasting models:
AR(p) Model (Autoregressive Model): The autoregressive model describes the relationship between current values and historical values
MA(q) model (Moving Average Model): The moving average model describes the accumulation of errors in the autoregressive part
ARMA model:The so-called ARMA model refers toconverting non-stationary time series into stationary time series, and then build a model by regressing the dependent variable only on its lagged value and the present value and lagged value of the random error term.