PREDICT_AUTOREGRESSOR

Applies an autoregressor (AR) model to an input relation.

Applies an autoregressor (AR) or vector autoregression (VAR) model to an input relation. The function returns predictions for each value column specified during model creation.

AR and VAR models use previous values to make predictions. During model training, the user specifies the number of lagged timesteps taken into account during computation. The model predicts future values as a linear combination of the timeseries values at each lag.

Syntax

PREDICT_AUTOREGRESSOR ( timeseries-columns
        USING PARAMETERS model_name = 'model-name' [, param=value[,...] ] )
        OVER (ORDER BY timestamp-column)
        FROM input-relation

Arguments

timeseries-columns
The timeseries columns used to make predictions. The number of timeseries-columns must be the same as the number of value columns provided during model training.

For each prediction, the model only considers the previous P values of each column, where P is the lag set during model creation.

timestamp-column
The timestamp column, with consistent timesteps, used to make the prediction.
input-relation
The input relation containing the timeseries-columns and timestamp-column.

The input-relation cannot have missing values in any of the P rows preceding start, where P is the lag set during model creation. To handle missing values, see IMPUTE or Linear interpolation.

Parameters

model_name

Name of the model (case-insensitive).

start
INTEGER >p or ≤0, the index (row) of the input-relation at which to start the prediction. If omitted, the prediction starts at the end of the input-relation.

If the start index is greater than the number of rows N in timeseries-columns, then the values between N and start are predicted and used for the prediction.

If negative, the start index is identified by counting backwards from the end of the input-relation.

For an input-relation of N rows, negative values have a lower limit of either -1000 or -(N-p), whichever is greater.

Default: the end of input-relation

npredictions
INTEGER ≥1, the number of predicted timesteps.

Default: 10

missing
One of the following methods for handling missing values:
  • drop: Missing values are ignored.

  • error: Missing values raise an error.

  • zero: Missing values are replaced with 0.

  • linear_interpolation: Missing values are replaced by linearly-interpolated values based on the nearest valid entries before and after the missing value. If all values before or after a missing value in the prediction range are missing or invalid, interpolation is impossible and the function errors. VAR models do not support linear interpolation.

Default: Method used when training the model

Examples

The following example makes predictions using an AR model for 10 timesteps after the end of the input relation:

=> SELECT PREDICT_AUTOREGRESSOR(Temperature USING PARAMETERS model_name='AR_temperature', npredictions=10) 
  OVER(ORDER BY time) FROM temp_data;
 index |    prediction
-------+------------------
     1 | 12.6235419917807
     2 | 12.9387860506032
     3 | 12.6683380680058
     4 | 12.3886937385419
     5 | 12.2689506237424
     6 | 12.1503023330142
     7 | 12.0211734746741
     8 | 11.9150531529328
     9 | 11.825870404008
    10 | 11.7451846722395
(10 rows)

The following example makes predictions using a VAR model for 10 timesteps after the end of the input relation:

=> SELECT PREDICT_AUTOREGRESSOR(temp_location1, temp_location2 USING PARAMETERS 
  model_name='VAR_temperature', npredictions=10) OVER(ORDER BY time) FROM temp_data_VAR;  
 index |  temp_location1  |  temp_location2
-------+------------------+------------------
     1 | 11.7583950082813 | 12.7193948948294
     2 | 11.8492948294829 | 12.2400294852222
     3 | 11.9917382847772 | 13.8385038582000
     4 | 11.2302988673747 | 13.1174827497563
     5 | 11.8920481717273 | 13.1948776593788
     6 | 12.1737583757385 | 12.7362846366622
     7 | 12.0397364321183 | 12.9274628462844
     8 | 12.0395726450372 | 12.1749275028444
     9 | 11.8249947849488 | 12.3274926927433
    10 | 11.1129497288422 | 12.1749274927493
(10 rows)

See Autoregressive model example and VAR model example for extended examples.

See also