foundationforecast.prophet.FoundationProphet
FoundationProphet
FoundationProphet(
model: Forecaster | None = None,
interval_width: float = 0.8,
insample: Literal["cv", "none"] = "cv",
insample_h: int | None = None,
insample_n_windows: int | None = None,
**prophet_kwargs: Any
)
Bases: Prophet
prophet.Prophet with a foundation model instead of the Stan model.
Use it to swap a foundation model into an existing Prophet pipeline: the
fit, make_future_dataframe, predict and plot calls keep working and
predict returns the usual ds, yhat, yhat_lower and yhat_upper
columns.
import numpy as np
import pandas as pd
from foundationforecast.models import Chronos
from foundationforecast.prophet import FoundationProphet
ds = pd.date_range("2024-01-01", periods=120, freq="D")
df = pd.DataFrame({"ds": ds, "y": 10 + np.sin(np.arange(120) * 2 * np.pi / 7)})
model = Chronos(repo_id="amazon/chronos-bolt-tiny")
m = FoundationProphet(model=model) # instead of Prophet()
m.fit(df)
future = m.make_future_dataframe(periods=14, include_history=False)
forecast = m.predict(future)
assert list(forecast.columns) == ["ds", "yhat", "yhat_lower", "yhat_upper"]
Foundation models are zero-shot, so fit only stores the history. The
forecast is produced in predict, and the interval covers
interval_width of the predictive distribution.
Historical dates in the dataframe given to predict (what
make_future_dataframe(include_history=True) returns, and Prophet's
default) have no fitted values. With insample="cv" they are filled with
rolling-origin backtest forecasts from model.cross_validation, which
runs the model once per window. A message is logged the first time this
happens. Use insample="none" or make_future_dataframe(include_history=False)
to skip it; historical rows are then NaN.
Columns registered with add_regressor are passed to the model as
known-future exogenous variables, so the wrapped model must support them
(see the exogenous variables guide). Prophet-specific options (growth,
holidays, seasonalities, changepoints, ...) are accepted for
compatibility but have no effect, and a UserWarning says so.
plot_components and the posterior sampling methods are not available.
The history must be on a regular grid with no gaps (rows with a null y
are dropped, so an interior one counts as a gap): its frequency is inferred
from ds and the dates requested in predict must lie on that grid.
Create the adapter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Forecaster | None
|
Foundation model (any |
None
|
interval_width
|
float
|
Width of the prediction interval reported in
|
0.8
|
insample
|
Literal['cv', 'none']
|
How to fill historical dates in |
'cv'
|
insample_h
|
int | None
|
Horizon of each backtest window. Defaults to the
number of future periods in |
None
|
insample_n_windows
|
int | None
|
Maximum number of backtest windows, counted back from the end of the history. Defaults to 10. Fewer windows are used when the history is short. |
None
|
**prophet_kwargs
|
Any
|
Remaining |
{}
|
fit
fit(df: DataFrame, **kwargs: Any) -> FoundationProphet
Store the history; foundation models need no training.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Dataframe with the dates in |
required |
**kwargs
|
Any
|
Accepted for compatibility with |
{}
|
Returns:
| Type | Description |
|---|---|
FoundationProphet
|
The fitted adapter. |
predict
predict(
df: DataFrame | None = None, vectorized: bool = True
) -> DataFrame
Forecast the dates in df.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame | None
|
Dataframe with the dates in |
None
|
vectorized
|
bool
|
Accepted for compatibility with |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Dataframe with |
add_regressor
add_regressor(
name: str, *args: Any, **kwargs: Any
) -> FoundationProphet
Register a known-future exogenous variable passed to the model.