In this article, we present the WarpScript extension for time series forecasting and show an exemple on power consumption data and another one on air passenger data.

A time series forecast is a regression problem, for which the input is a series of past values, and the result is the prediction of one or more values in the future.

In WarpScript, a paid extension called Warp10-ext-forecasting offers a set of WarpScript functions to find suitable forecast models on GTS and make predictions.

The Warp10-ext-forecasting is installed on the sandbox instance, so you can try it for free.

The documentation is avalaible on its WarpFleet page.

## Presentation of the forecasting extension

This extension introduces the class of GTS forecast models, its WarpScript type is `X-GTSFORECASTMODEL`

. Here, the `X`

prefix means that this type is introduced by an extension.

A set of functions build and train forecast models. As can be seen in the document, multiple families of forecast models are implemented:

- auto-regressive integrated moving averages models
- e.g.
`ARIMA`

,`SARIMA`

- e.g.
- exponential smoothing models (including holt-winters)
- e.g.
`SES`

,`HOLTWINTERS`

- e.g.
- neural network models
- e.g.
`LSTM`

,`NNETAR`

- e.g.

Another set of auto-ML functions allow the user to search for the best model and automatically choose the right hyper-parameters, e.g. the `AUTO`

function.

Then, of course, there are also functions that take the GTS forecast model as argument. For example, `FORECAST`

makes an actual forecast, and `FORECAST.ANOMALIES`

uses a forecast in the past to detect outliers using real values against predictions.

Let's look at some examples.

## Example 1: power consumption forecast

In this example, we will make use of power consumption data that is compressed in the macro `@senx/dataset/power_consumption`

.

For example, in the code below, we make a forecast using a model of type `SARIMA`

(here the letter `S`

stands for seasonal).

```
# prepare the data: it needs ot be bucketized
@senx/dataset/power_consumption -1000 SHRINK
[ SWAP bucketizer.last 0 30 m 0 ] BUCKETIZE 'input_data' STORE
# plot the original data
$input_data
# compute the forecast model (here we search for a SARIMA model with seasonality of 48 points i.e. 1 day)
# make a forecast for the next week and leave the gts to be plotted
$input_data 48 SEARCH.SARIMA
48 7 * FORECAST
```

https://snapshot.senx.io/0005a7cf9faee104-0-0-7d7e47060d55011e

## Example 2: Air Passengers forecast

In this example, we compare multiple forecast models for predicting the number of passengers of an airline company. Note that as a preprocessing transform, we bucketize by month. you can learn more about this in a previous blog post.

```
@senx/dataset/air_passengers_monthly
# preprocessing transform (bucketize by month)
[ SWAP bucketizer.mean ] @senx/cal/BUCKETIZE.bymonth
0 GET 'data' STORE
# train multiple forecast models that are quick to converge
[
$data SEARCH.ARIMA 48 FORECAST { 'method' 'search.arima' } RELABEL
$data 12 SEARCH.SARIMA 48 FORECAST { 'method' 'search.sarima' } RELABEL
{ 'gts' $data 'max evals' 10000 } SES 48 FORECAST { 'method' 'ses' } RELABEL
{ 'gts' $data 'cycle' 12 'max evals' 10000 } HOLTWINTERS 48 FORECAST { 'method' 'holtwinters' } RELABEL
$data -50 SHRINK
]
# invert the preprocessing tranform
[ SWAP bucketizer.last 0 1 0 ] BUCKETIZE
UNBUCKETIZE.CALENDAR
```

https://snapshot.senx.io/0005a7d092fddda0-0-0-66f440d24f3b3339

It seems that SARIMA models (standing for Seasonal Auto Regressive Integrated Moving Average) are better suited to forecast this time series.

As an exercise, you can try the function SAUTO. You will see that it obtains the same forecast than with this SARIMA model.

## Conclusion

The Warp10-ext-forecast brings forecasting functions to enhance your WarpScripts. This is a private extension that can be made available on your instance. You can reach us at contact@senx.io if you wish to do so. It is also available on the sandbox instance for free.

### Read more

**Fetch the first datapoint in Warp 10**

In Warp 10, finding the first tick of a time series can be tricky. This article shows you a simple solution with WarpScript.

**I want this in Excel!**

Export time series (GTS) into a csv. It seems easy. Doing this exercise is the best way to measure the gap between a timeseries database and Excel!