The Forecasting Company Logo
Cookbook

Forecast several columns at once

You have more than one number to predict per series — sales and returns, for example. Give each one the "target" kind and both are forecast in the same request:

JSONCode
{ "input": { "source": { "inline": { "date": ["2024-01-01", "2024-01-02", "2024-01-03"], "store": ["S1", "S1", "S1"], "sales": [142, 137, 145], "returns": [6, 4, 9] } }, "columns": { "date": { "kind": "time", "frequency": "1d" }, "store": "identifier", "sales": { "kind": "target", "aggregate": "sum" }, "returns": { "kind": "target", "aggregate": "sum" } } }, "prediction_length": "2w", "quantiles": [0.1, 0.5, 0.9] }

Post it to https://api.retrocast.com/v1-beta/forecast?model=t0-alpha. model names the forecasting model and is required — without it the request is rejected with missing field "model".

There is no targets field in this request. Leave it out and every column with the "target" kind is forecast.

Forecast only some of them

To forecast a subset without editing the schema, list the columns you want in targets:

JSONCode
"targets": ["sales"]

The names must be columns you declared as targets. returns stays in the data as history the model can use, but no forecast is returned for it.

What comes back

data.targets is keyed by column name, one entry per forecast column. The arrays below are trimmed to the first two of the 14 steps:

JSONCode
{ "data": { "time": ["2024-01-04T00:00:00Z", "2024-01-05T00:00:00Z"], "cutoff": ["2024-01-03T00:00:00Z", "2024-01-03T00:00:00Z"], "lead_time": ["PT0S", "P1D"], "span": ["P1D", "P1D"], "identifiers": { "store": ["S1", "S1"] }, "targets": { "sales": { "quantiles": { "0.1": [137.7, 137.5], "0.5": [141.0, 140.5], "0.9": [147.4, 146.2] } }, "returns": { "quantiles": { "0.1": [4.1, 4.1], "0.5": [6.2, 5.8], "0.9": [10.4, 9.5] } } } } }

Every target shares one time axis and one set of levels: prediction_length, cutoff, lead_time and quantiles are set once for the request and apply to all of them. With compute_metrics: true, each entry in metrics is keyed by target column the same way, so you get separate scores per column.

Last modified on