Forecaster that wraps a FoundationModel for full skforecast ecosystem
compatibility: backtesting, model selection, etc.
Unlike ML-based forecasters, there is no training step — the underlying
foundation models are zero-shot. fit only stores the context
(recent observations) and records index metadata. Predictions are generated
directly by the model's predict_quantiles pipeline.
Supports both single-series and multi-series modes. Pass a pandas.Series
to fit for single-series forecasting or a wide pandas.DataFrame, a
long-format pandas.DataFrame (MultiIndex), or a dict[str, pd.Series]
for multi-series (global-model) forecasting.
A configured FoundationModel instance, e.g.
FoundationModel("autogluon/chronos-2-small", context_length=512).
See FoundationModel for the list of supported model_id values
and adapter-specific parameters.
Per-series dict of pandas Series containing the last context_length
observations from the training data. Delegates to
estimator.context_. None before fitting.
Per-series dict of pandas DataFrame containing the last
context_length exogenous variables from the training data.
Delegates to estimator.context_exog_. None before fitting or
if no exogenous variables were provided.
Frequency of the index of the input used in training. A
pandas.DateOffset for DatetimeIndex; the step integer
for RangeIndex. Delegates to estimator.index_freq_.
First and last values of index of the data used during training.
A dict keyed by series name with pandas.Index values.
Delegates to estimator.context_range_.
Per-series dict of pandas Series containing the last
context_length observations from the training data.
Delegates to estimator.context_. None before fitting.
Per-series dict of pandas DataFrame containing the last
context_length exogenous variables from the training data.
Delegates to estimator.context_exog_. None before fitting
or if no exogenous variables were provided.
Returns the first and last max_items // 2 elements (joined by
'...') when the list exceeds max_items. Returns a shallow
copy so callers can mutate the result freely.
Parameters:
Name
Type
Description
Default
names
(list, None)
Names to truncate. If None, returns None.
required
max_items
int
Maximum number of names to keep before truncation.
50
Returns:
Name
Type
Description
truncated
(list, None)
Truncated list, or None if names is None.
Source code in skforecast/foundation/_forecaster_foundation.py
@staticmethoddef_truncate_names(names:list[str]|None,max_items:int=50,)->list[str]|None:""" Truncate a list of names for display. Returns the first and last `max_items // 2` elements (joined by `'...'`) when the list exceeds `max_items`. Returns a shallow copy so callers can mutate the result freely. Parameters ---------- names : list, None Names to truncate. If `None`, returns `None`. max_items : int, default 50 Maximum number of names to keep before truncation. Returns ------- truncated : list, None Truncated list, or `None` if `names` is `None`. """ifnamesisNone:returnNonenames=list(names)iflen(names)>max_items:half=max_items//2names=names[:half]+["..."]+names[-half:]returnnames
Truncates the list to the first and last max_items // 2 elements
(joined by '...') when it exceeds max_items, then wraps the
resulting string with textwrap.fill when it exceeds
max_text_length characters.
Parameters:
Name
Type
Description
Default
names
(list, None)
Names to format. If None, returns None.
required
max_items
int
Maximum number of names to display before truncation.
50
max_text_length
int
Maximum length of the joined string before text wrapping.
58
Returns:
Name
Type
Description
formatted
(str, None)
Formatted string, or None if names is None.
Source code in skforecast/foundation/_forecaster_foundation.py
@staticmethoddef_format_names_repr(names:list[str]|None,max_items:int=50,max_text_length:int=58,)->str|None:""" Format a list of names for text `__repr__`. Truncates the list to the first and last `max_items // 2` elements (joined by `'...'`) when it exceeds `max_items`, then wraps the resulting string with `textwrap.fill` when it exceeds `max_text_length` characters. Parameters ---------- names : list, None Names to format. If `None`, returns `None`. max_items : int, default 50 Maximum number of names to display before truncation. max_text_length : int, default 58 Maximum length of the joined string before text wrapping. Returns ------- formatted : str, None Formatted string, or `None` if `names` is `None`. """names=ForecasterFoundation._truncate_names(names,max_items)ifnamesisNone:returnNoneformatted=", ".join(names)iflen(formatted)>max_text_length:formatted="\n "+textwrap.fill(formatted,width=80,subsequent_indent=" ")returnformatted
Stores index metadata and delegates context storage to the underlying
adapter. No model training occurs since foundation model is zero-shot.
Parameters:
Name
Type
Description
Default
series
pandas Series, pandas DataFrame, dict
Training time series.
If pandas.Series: single-series mode.
If wide pandas.DataFrame (one column per series): multi-series
mode.
If long-format pandas.DataFrame with a MultiIndex (first level =
series IDs, second level = DatetimeIndex): multi-series
mode. Internally converted to a dict. An InputTypeWarning is
issued; consider passing a dict directly for better performance.
If dict[str, pd.Series]: multi-series mode.
required
exog
pandas Series, pandas DataFrame, dict
Historical exogenous variables aligned to series. At prediction
time they are forwarded to the underlying adapter as past
(historical) covariates, using the adapter-specific covariate
format.
In single-series mode: pd.Series or pd.DataFrame aligned to
series.
In multi-series mode: a dict[str, pd.Series | pd.DataFrame | None]
with one entry per series, a single pd.Series / pd.DataFrame
broadcast to all series, or a long-format pd.DataFrame with a
MultiIndex (first level = series IDs, second level =
DatetimeIndex). Long-format inputs are converted to a dict
internally; an InputTypeWarning is issued.
None
Returns:
Type
Description
None
Source code in skforecast/foundation/_forecaster_foundation.py
deffit(self,series:pd.Series|pd.DataFrame|dict[str,pd.Series],exog:(pd.Series|pd.DataFrame|dict[str,pd.Series|pd.DataFrame|None]|None)=None,)->None:""" Training Forecaster. Stores index metadata and delegates context storage to the underlying adapter. No model training occurs since foundation model is zero-shot. Parameters ---------- series : pandas Series, pandas DataFrame, dict Training time series. - If `pandas.Series`: single-series mode. - If wide `pandas.DataFrame` (one column per series): multi-series mode. - If long-format `pandas.DataFrame` with a MultiIndex (first level = series IDs, second level = `DatetimeIndex`): multi-series mode. Internally converted to a dict. An `InputTypeWarning` is issued; consider passing a dict directly for better performance. - If `dict[str, pd.Series]`: multi-series mode. exog : pandas Series, pandas DataFrame, dict, default None Historical exogenous variables aligned to `series`. At prediction time they are forwarded to the underlying adapter as past (historical) covariates, using the adapter-specific covariate format. In single-series mode: `pd.Series` or `pd.DataFrame` aligned to `series`. In multi-series mode: a `dict[str, pd.Series | pd.DataFrame | None]` with one entry per series, a single `pd.Series` / `pd.DataFrame` broadcast to all series, or a long-format `pd.DataFrame` with a MultiIndex (first level = series IDs, second level = `DatetimeIndex`). Long-format inputs are converted to a `dict` internally; an `InputTypeWarning` is issued. Returns ------- None """self.is_fitted=FalseifexogisnotNoneandnotself.estimator.allow_exog:warnings.warn(f"The model '{self.estimator.model_id}' does not support "f"exogenous variables. `exog` will be ignored.",IgnoredArgumentWarning,stacklevel=2,)exog=Noneself.estimator.fit(series=series,exog=exog)self.is_fitted=True
Subset of series to predict. If None, all series in context are
predicted.
None
context
pandas Series, pandas DataFrame, dict
Context override for backtesting. When provided, replaces the
context stored at fit time. In single-series mode pass a
pd.Series; in multi-series mode pass a wide pd.DataFrame or a
dict[str, pd.Series]. If longer than context_length, only the
last context_length observations are used. If shorter, all
available observations are passed as-is and the model handles the
reduced context gracefully.
None
context_exog
pandas Series, pandas DataFrame, dict
Historical exogenous variables aligned to context (past
covariates, mapped to the adapter-specific covariate format).
None
exog
pandas Series, pandas DataFrame, dict
Future-known exogenous variables for the forecast horizon (future
covariates, mapped to the adapter-specific covariate format).
Must cover exactly steps steps for each series.
None
check_inputs
bool
If True, the context and context_exog inputs are validated
and normalized. If False, context must already be a
dict[str, pandas Series] and context_exog must be a
dict[str, pandas DataFrame | None] or None. This argument
is created for internal use and is not recommended to be changed.
True
Returns:
Name
Type
Description
predictions
pandas DataFrame
Long-format DataFrame with columns ['level', 'pred'].
The index repeats each forecast timestamp once per series.
Notes
Foundation models are pre-trained and do not learn from the data passed
to fit. The fit method only stores context (the last context_length
observations) and metadata. This leads to four distinct behaviors
depending on the combination of is_fitted and context:
Not fitted, context=None: raises NotFittedError. There is no
context available for prediction.
Fitted, context=None: uses the context and context_exog_ stored
during fit. If the user supplies context_exog, it is ignored with a
warning.
Not fitted, context provided (zero-shot mode): The model uses
context and context_exog (if provided) as context for prediction.
Fitted, context provided: Stored context is ignored, the
provided context and context_exog (if provided) are used for
prediction.
Source code in skforecast/foundation/_forecaster_foundation.py
defpredict(self,steps:int,levels:str|list[str]|None=None,context:pd.Series|pd.DataFrame|dict[str,pd.Series]|None=None,context_exog:(pd.Series|pd.DataFrame|dict[str,pd.DataFrame|pd.Series|None]|None)=None,exog:(pd.Series|pd.DataFrame|dict[str,pd.Series|pd.DataFrame|None]|None)=None,check_inputs:bool=True,)->pd.DataFrame:""" Predict n steps ahead. Parameters ---------- steps : int Number of steps ahead to forecast. levels : str, list, default None Subset of series to predict. If `None`, all series in `context` are predicted. context : pandas Series, pandas DataFrame, dict, default None Context override for backtesting. When provided, replaces the context stored at fit time. In single-series mode pass a `pd.Series`; in multi-series mode pass a wide `pd.DataFrame` or a `dict[str, pd.Series]`. If longer than `context_length`, only the last `context_length` observations are used. If shorter, all available observations are passed as-is and the model handles the reduced context gracefully. context_exog : pandas Series, pandas DataFrame, dict, default None Historical exogenous variables aligned to `context` (past covariates, mapped to the adapter-specific covariate format). exog : pandas Series, pandas DataFrame, dict, default None Future-known exogenous variables for the forecast horizon (future covariates, mapped to the adapter-specific covariate format). Must cover exactly `steps` steps for each series. check_inputs : bool, default True If `True`, the `context` and `context_exog` inputs are validated and normalized. If `False`, `context` must already be a `dict[str, pandas Series]` and `context_exog` must be a `dict[str, pandas DataFrame | None]` or `None`. This argument is created for internal use and is not recommended to be changed. Returns ------- predictions : pandas DataFrame Long-format DataFrame with columns `['level', 'pred']`. The index repeats each forecast timestamp once per series. Notes ----- Foundation models are pre-trained and do not learn from the data passed to `fit`. The `fit` method only stores context (the last `context_length` observations) and metadata. This leads to four distinct behaviors depending on the combination of `is_fitted` and `context`: - **Not fitted, `context=None`**: raises `NotFittedError`. There is no context available for prediction. - **Fitted, `context=None`**: uses the context and `context_exog_` stored during `fit`. If the user supplies `context_exog`, it is ignored with a warning. - **Not fitted, `context` provided (zero-shot mode)**: The model uses `context` and `context_exog` (if provided) as context for prediction. - **Fitted, `context` provided**: Stored context is ignored, the provided `context` and `context_exog` (if provided) are used for prediction. """ifnotself.is_fittedandcontextisNone:raiseNotFittedError("This forecaster is not fitted yet. Call `fit` with appropriate ""arguments before using `predict()`, or pass `context`.")predictions=self.estimator.predict(steps=steps,context=context,context_exog=context_exog,exog=exog,quantiles=None,levels=levels,check_inputs=check_inputs,)returnpredictions
Prediction intervals are derived directly from the underlying
foundation model's native quantile output — no bootstrapping or
residual estimation is used.
Parameters:
Name
Type
Description
Default
steps
int
Number of steps ahead to forecast.
required
levels
(str, list)
Subset of series to predict. If None, all series in context are
predicted.
None
context
pandas Series, pandas DataFrame, dict
Context override for backtesting.
None
context_exog
pandas Series, pandas DataFrame, dict
Historical exog aligned to context (past covariates).
None
exog
pandas Series, pandas DataFrame, dict
Future-known exogenous variables for the forecast horizon
(future covariates).
None
interval
(list, tuple)
Confidence of the prediction interval. Sequence of two percentiles
[lower, upper], e.g. [10, 90] for an 80 % interval.
Values must be between 0 and 100 inclusive.
[10, 90]
check_inputs
bool
If True, the context and context_exog inputs are validated
and normalized. If False, context must already be a
dict[str, pandas Series] and context_exog must be a
dict[str, pandas DataFrame | None] or None. This argument
is created for internal use and is not recommended to be changed.
True
Returns:
Name
Type
Description
predictions
pandas DataFrame
Long-format DataFrame with columns ['level', 'pred', 'lower_bound',
'upper_bound'].
Notes
Foundation models are pre-trained and do not learn from the data passed
to fit. The fit method only stores context (the last context_length
observations) and metadata. This leads to four distinct behaviors
depending on the combination of is_fitted and context:
Not fitted, context=None: raises NotFittedError. There is no
context available for prediction.
Fitted, context=None: uses the context and context_exog_ stored
during fit. If the user supplies context_exog, it is ignored with a
warning.
Not fitted, context provided (zero-shot mode): The model uses
context and context_exog (if provided) as context for prediction.
Fitted, context provided: Stored context is ignored, the
provided context and context_exog (if provided) are used for
prediction.
Source code in skforecast/foundation/_forecaster_foundation.py
defpredict_interval(self,steps:int,levels:str|list[str]|None=None,context:pd.Series|pd.DataFrame|dict[str,pd.Series]|None=None,context_exog:(pd.Series|pd.DataFrame|dict[str,pd.DataFrame|pd.Series|None]|None)=None,exog:(pd.Series|pd.DataFrame|dict[str,pd.Series|pd.DataFrame|None]|None)=None,interval:list[float]|tuple[float]=[10,90],check_inputs:bool=True,)->pd.DataFrame:""" Predict n steps ahead with prediction intervals. Prediction intervals are derived directly from the underlying foundation model's native quantile output — no bootstrapping or residual estimation is used. Parameters ---------- steps : int Number of steps ahead to forecast. levels : str, list, default None Subset of series to predict. If `None`, all series in `context` are predicted. context : pandas Series, pandas DataFrame, dict, default None Context override for backtesting. context_exog : pandas Series, pandas DataFrame, dict, default None Historical exog aligned to `context` (past covariates). exog : pandas Series, pandas DataFrame, dict, default None Future-known exogenous variables for the forecast horizon (future covariates). interval : list, tuple, default [10, 90] Confidence of the prediction interval. Sequence of two percentiles `[lower, upper]`, e.g. `[10, 90]` for an 80 % interval. Values must be between 0 and 100 inclusive. check_inputs : bool, default True If `True`, the `context` and `context_exog` inputs are validated and normalized. If `False`, `context` must already be a `dict[str, pandas Series]` and `context_exog` must be a `dict[str, pandas DataFrame | None]` or `None`. This argument is created for internal use and is not recommended to be changed. Returns ------- predictions : pandas DataFrame Long-format DataFrame with columns `['level', 'pred', 'lower_bound', 'upper_bound']`. Notes ----- Foundation models are pre-trained and do not learn from the data passed to `fit`. The `fit` method only stores context (the last `context_length` observations) and metadata. This leads to four distinct behaviors depending on the combination of `is_fitted` and `context`: - **Not fitted, `context=None`**: raises `NotFittedError`. There is no context available for prediction. - **Fitted, `context=None`**: uses the context and `context_exog_` stored during `fit`. If the user supplies `context_exog`, it is ignored with a warning. - **Not fitted, `context` provided (zero-shot mode)**: The model uses `context` and `context_exog` (if provided) as context for prediction. - **Fitted, `context` provided**: Stored context is ignored, the provided `context` and `context_exog` (if provided) are used for prediction. """ifnotself.is_fittedandcontextisNone:raiseNotFittedError("This forecaster is not fitted yet. Call `fit` with appropriate ""arguments before using `predict_interval()`, or pass `context`.")ifisinstance(interval,(int,float)):check_interval(alpha=interval,alpha_literal='interval')interval=[(0.5-interval/2)*100,(0.5+interval/2)*100]iflen(interval)!=2:raiseValueError(f"`interval` must be a sequence of exactly two values [lower, upper]. "f"Got {len(interval)} values.")lower_pct,upper_pct=float(interval[0]),float(interval[1])ifnot(0<=lower_pct<upper_pct<=100):raiseValueError(f"`interval` values must satisfy 0 <= lower < upper <= 100. "f"Got [{lower_pct}, {upper_pct}].")lower_q=lower_pct/100upper_q=upper_pct/100# Always include the median (0.5) so 'pred' is the central forecast.quantiles=sorted({lower_q,0.5,upper_q})predictions=self.predict_quantiles(steps=steps,levels=levels,context=context,context_exog=context_exog,exog=exog,quantiles=quantiles,check_inputs=check_inputs,)predictions=predictions[['level',f'q_{0.5}',f'q_{lower_q}',f'q_{upper_q}']]predictions.columns=['level','pred','lower_bound','upper_bound']returnpredictions
Predict n steps ahead at specified quantile levels.
Parameters:
Name
Type
Description
Default
steps
int
Number of steps ahead to forecast.
required
levels
(str, list)
Subset of series to predict. If None, all series in context are
predicted.
None
context
pandas Series, pandas DataFrame, dict
Context override for backtesting.
None
context_exog
pandas Series, pandas DataFrame, dict
Historical exog aligned to context (past covariates).
None
exog
pandas Series, pandas DataFrame, dict
Future-known exogenous variables for the forecast horizon
(future covariates).
None
quantiles
(list, tuple)
Quantile levels to forecast. Values must be in the range (0, 1).
[0.1, 0.5, 0.9]
check_inputs
bool
If True, the context and context_exog inputs are validated
and normalized. If False, context must already be a
dict[str, pandas Series] and context_exog must be a
dict[str, pandas DataFrame | None] or None. This argument
is created for internal use and is not recommended to be changed.
True
Returns:
Name
Type
Description
predictions
pandas DataFrame
Long-format DataFrame with columns ['level', 'q_0.1', 'q_0.5', ...].
Notes
Foundation models are pre-trained and do not learn from the data passed
to fit. The fit method only stores context (the last context_length
observations) and metadata. This leads to four distinct behaviors
depending on the combination of is_fitted and context:
Not fitted, context=None: raises NotFittedError. There is no
context available for prediction.
Fitted, context=None: uses the context and context_exog_ stored
during fit. If the user supplies context_exog, it is ignored with a
warning.
Not fitted, context provided (zero-shot mode): The model uses
context and context_exog (if provided) as context for prediction.
Fitted, context provided: Stored context is ignored, the
provided context and context_exog (if provided) are used for
prediction.
Source code in skforecast/foundation/_forecaster_foundation.py
defpredict_quantiles(self,steps:int,levels:str|list[str]|None=None,context:pd.Series|pd.DataFrame|dict[str,pd.Series]|None=None,context_exog:(pd.Series|pd.DataFrame|dict[str,pd.DataFrame|pd.Series|None]|None)=None,exog:(pd.Series|pd.DataFrame|dict[str,pd.Series|pd.DataFrame|None]|None)=None,quantiles:list[float]|tuple[float]=[0.1,0.5,0.9],check_inputs:bool=True,)->pd.DataFrame:""" Predict n steps ahead at specified quantile levels. Parameters ---------- steps : int Number of steps ahead to forecast. levels : str, list, default None Subset of series to predict. If `None`, all series in `context` are predicted. context : pandas Series, pandas DataFrame, dict, default None Context override for backtesting. context_exog : pandas Series, pandas DataFrame, dict, default None Historical exog aligned to `context` (past covariates). exog : pandas Series, pandas DataFrame, dict, default None Future-known exogenous variables for the forecast horizon (future covariates). quantiles : list, tuple, default [0.1, 0.5, 0.9] Quantile levels to forecast. Values must be in the range (0, 1). check_inputs : bool, default True If `True`, the `context` and `context_exog` inputs are validated and normalized. If `False`, `context` must already be a `dict[str, pandas Series]` and `context_exog` must be a `dict[str, pandas DataFrame | None]` or `None`. This argument is created for internal use and is not recommended to be changed. Returns ------- predictions : pandas DataFrame Long-format DataFrame with columns `['level', 'q_0.1', 'q_0.5', ...]`. Notes ----- Foundation models are pre-trained and do not learn from the data passed to `fit`. The `fit` method only stores context (the last `context_length` observations) and metadata. This leads to four distinct behaviors depending on the combination of `is_fitted` and `context`: - **Not fitted, `context=None`**: raises `NotFittedError`. There is no context available for prediction. - **Fitted, `context=None`**: uses the context and `context_exog_` stored during `fit`. If the user supplies `context_exog`, it is ignored with a warning. - **Not fitted, `context` provided (zero-shot mode)**: The model uses `context` and `context_exog` (if provided) as context for prediction. - **Fitted, `context` provided**: Stored context is ignored, the provided `context` and `context_exog` (if provided) are used for prediction. """ifnotself.is_fittedandcontextisNone:raiseNotFittedError("This forecaster is not fitted yet. Call `fit` with appropriate ""arguments before using `predict_quantiles()`, or pass `context`.")predictions=self.estimator.predict(steps=steps,context=context,context_exog=context_exog,exog=exog,quantiles=list(quantiles),levels=levels,check_inputs=check_inputs,)returnpredictions
defset_params(self,params:dict[str,object])->None:""" Set new values to the parameters of the underlying estimator. After calling this method, the forecaster is reset to an unfitted state. Parameters ---------- params : dict Parameters values. Returns ------- None """self.estimator.set_params(**params)self.is_fitted=False