Time Series Forecasting#

You can train a forecasting model easily in EvaDB.

Note

Install statsforecast in your EvaDB virtual environment: pip install eva[forecasting].

First, we create a table to insert required data.

CREATE TABLE AirData (
 unique_id TEXT(30),
 ds TEXT(30),
 y INTEGER);

LOAD CSV 'data/forecasting/air-passengers.csv' INTO AirData;

Next, we create a UDF of TYPE Forecasting. We must enter the column name on which we wish to forecast using predict. Other options include id and time (they represent the unique id of the items and the time data if available).

CREATE UDF IF NOT EXISTS Forecast FROM
(SELECT y FROM AirData)
TYPE Forecasting
PREDICT 'y';

This trains a forecasting model. The model can be called by providing the horizon for forecasting.

SELECT Forecast(12) FROM AirData;

Here, the horizon is 12.