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 available 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:

- Autoregressive 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 hyperparameters, e.g. the `AUTO`

function.

Thinking in WarpScript: discover built-in functions that can be used for detecting anomalies in time series. |

Then, of course, there are also functions that take the GTS forecast model as an 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
[
$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 as with this SARIMA model.

## Conclusion

Learn more about how to Forecast with Facebook Prophet and CALL |

The Warp10-ext-forecast brings forecasting functions to enhance your WarpScript. 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

**Using Warp 10 as a map tile server for Discovery**

Discover how to use Warp 10 as a tiles server and plug it into Discovery

**Automatic Time Series archiving**

Learn how to manage the life cycle of your Time Series data by setting up automatic archiving of old data to an external system such as S3

**The Py4J plugin for Warp 10**

In this post, we explain how to install and use the Py4J plugin for Warp 10. This plugin allows Python scripts to interact with the WarpScript languag...

Machine Learning Engineer