Modeling and forecasting time series is a common task in many business verticals. Modeling is used to extract meaningful statistics and other characteristics of the data. Forecasting is the use of a model to predict future data. DLI provides a series of stochastic linear models to help users conduct online modeling and forecasting in real time.
Auto-Regressive Integrated Moving Average (ARIMA) is a classical model used for time series forecasting and is closely correlated with the AR, MA, and ARMA models.
Syntax
1 2 3 4 5 | AR_PRED(field, degree): Use the AR model to forecast new data. AR_COEF(field, degree): Return the weight of the AR model. ARMA_PRED(field, degree): Use the ARMA model to forecast new data. ARMA_COEF(field, degree): Return the weight of the ARMA model. ARIMA_PRED(field, degree, derivativeOrder): Use ARIMA to forecast new data. |
Parameter |
Mandatory |
Description |
Default Value |
---|---|---|---|
field |
Yes |
Name of the field, data in which is used for prediction, in the data stream. |
- |
degree |
No |
Defines how many steps in the past are going to be considered for the next prediction. Currently, only "p = q = degree" is allowed. |
5 |
derivativeOrder |
No |
Derivative order. Generally, this parameter is set to 1 or 2. |
1 |
Example
Separately use AR, ARMA, and ARIMA to forecast the time series ordered by rowtime.
1 2 3 4 5 | SELECT b, AR_PRED(b) OVER (ORDER BY rowtime ROWS BETWEEN 5 PRECEDING AND CURRENT ROW) AS ar, ARMA_PRED(b) OVER (ORDER BY rowtime ROWS BETWEEN 5 PRECEDING AND CURRENT ROW) AS arma, ARIMA_PRED(b) OVER (ORDER BY rowtime ROWS BETWEEN 5 PRECEDING AND CURRENT ROW) AS arima FROM MyTable |
The Holt-Winters algorithm is one of the Exponential smoothing methods used to forecast seasonal data in time series.
Syntax
1 | HOLT_WINTERS(field, seasonality, forecastOrder) |
Parameter |
Mandatory |
Description |
---|---|---|
field |
Yes |
Name of the field, data in which is used for prediction, in the data stream. |
seasonality |
Yes |
Seasonality space used to perform the prediction. For example, if data samples are collected daily, and the season space to consider is a week, then seasonality is 7. |
forecastOrder |
No |
Value to be forecast, specifically, the number of steps to be considered in the future for producing the forecast. If forecastOrder is set to 1, the algorithm forecasts the next value. If forecastOrder is set to 2, the algorithm forecasts the value of 2 steps ahead in the future. The default value is 1. When using this parameter, ensure that the OVER window size is greater than the value of this parameter. |
Example
Use Holt-Winters to forecast time series ordered by rowtime.
1 2 3 4 | SELECT b, HOLT_WINTERS(b, 5) OVER (ORDER BY rowtime ROWS BETWEEN 5 PRECEDING AND CURRENT ROW) AS a1, HOLT_WINTERS(b, 5, 2) OVER (ORDER BY rowtime ROWS BETWEEN 5 PRECEDING AND CURRENT ROW) AS a2 FROM MyTable |