Skip to content

Reading a forecast ​

predict returns one forecast for each row you asked about. Each forecast contains:

FieldMeaning
timestampThe date as a number of milliseconds. Use new Date(timestamp) to read it.
valueThe forecast itself
trendThe long-term trend's share of the value
seasonalitiesOne entry per seasonal pattern, such as weekly or yearly
eventsOne entry per holiday or event
regressorsOne entry per extra factor
additiveAll additive pieces added up
multiplicativeAll multiplicative pieces added up, as a fraction (0.1 means +10%)

Example ​

ts
import { Effect } from "effect";
import { fit, predict, prophetFittingBackendLayer } from "effect-prophet";

const history = Array.from({ length: 90 }, (_, day) => ({
  timestamp: new Date(Date.UTC(2025, 0, 1 + day)).toISOString(),
  value: 100 + day * 0.5 + 10 * Math.sin((2 * Math.PI * day) / 7),
}));

const forecast = await Effect.runPromise(
  Effect.gen(function* () {
    const model = yield* fit(history);

    return yield* predict(model, ["2025-04-01T00:00:00.000Z"]);
  }).pipe(Effect.provide(prophetFittingBackendLayer)),
);

const [row] = forecast;

if (row !== undefined) {
  console.log("date:", new Date(row.timestamp).toISOString());
  console.log("forecast:", row.value.toFixed(2));
  console.log("trend:", row.trend.toFixed(2));

  for (const seasonality of row.seasonalities) {
    if (seasonality.mode === "additive") {
      console.log(`${seasonality.name}:`, seasonality.value.toFixed(2));
    }
  }
}
txt
date: 2025-04-01T00:00:00.000Z
forecast: 137.18
trend: 145.00
weekly: -7.82

On this day the trend alone predicts 145. Tuesday is a quiet day of the week, so the weekly pattern takes away 7.82, leaving a forecast of 137.18.

Additive and multiplicative pieces ​

Most pieces are additive: they add or subtract a fixed amount, like "+20 sales on Saturdays". Their entries have a value.

A piece can also be multiplicative: it changes the value by a percentage, like "+15% on Saturdays". Their entries have a factor (0.15 means +15%) and a contribution, which is the same effect converted into your data's units. See Seasonality.

The pieces always add back up:

txt
value = trend × (1 + multiplicative) + additive

Inspired by Prophet from Meta. Not affiliated with Meta.