Plans¶
The configuration that runs. ForecastPlan is returned by plan() and refine_plan(), and rendered into a script by forecast_code() and backtest_code(). The other models of this page describe its parts and the overrides that the methods of the assistant accept.
skforecast_ai.schemas.plans ¶
Classes:
| Name | Description |
|---|---|
CVParams |
LLM-produced cross-validation parameters for |
PreprocessingStep |
A preprocessing action required before forecasting. |
WindowFeature |
A single rolling-window feature specification for a forecaster. |
PlanOverrides |
LLM-produced overrides for a forecasting plan. |
RefinePlanOverrides |
Keyword overrides accepted by |
CandidateConfig |
Configuration of one candidate in |
ForecastPlan |
Detailed forecasting plan produced from a |
Attributes:
| Name | Type | Description |
|---|---|---|
OverrideName |
Decisions of a plan that the user can make instead of the rules of |
|
OVERRIDE_NAMES |
tuple[str, ...]
|
|
REFINE_PLAN_OVERRIDE_KEYS |
frozenset[str]
|
|
CANDIDATE_CONFIG_KEYS |
frozenset[str]
|
|
Attributes¶
OverrideName
module-attribute
¶
OverrideName = Literal[
"forecaster",
"estimator",
"estimator_kwargs",
"lags",
"window_features",
"metric",
"use_exog",
"differentiation",
"calendar_features",
"target_transformer",
"dropna_from_series",
]
Decisions of a plan that the user can make instead of the rules of
plan(), as recorded in ForecastPlan.overridden_fields.
REFINE_PLAN_OVERRIDE_KEYS
module-attribute
¶
REFINE_PLAN_OVERRIDE_KEYS = frozenset(
RefinePlanOverrides.__annotations__
)
CANDIDATE_CONFIG_KEYS
module-attribute
¶
CANDIDATE_CONFIG_KEYS = frozenset(
CandidateConfig.__annotations__
)
Classes¶
CVParams ¶
Bases: BaseModel
LLM-produced cross-validation parameters for TimeSeriesFold.
Returned as structured output from the CV configuration agent. All fields have defaults so the LLM only needs to specify the parameters it wants to override from the deterministic baseline.
Attributes:
| Name | Type | Description |
|---|---|---|
initial_train_size |
(int, float, str)
|
Number of observations (int), fraction of data (float in (0, 1)), or ISO date string marking the end of the initial training set (only when the dataset has a datetime index). |
refit |
(bool, int)
|
Whether to refit every fold (True), never (False), or every n folds (int). |
fixed_train_size |
bool
|
If True, training size stays fixed; if False, expands. |
gap |
int
|
Observations between end of training and start of test. |
fold_stride |
(int, None)
|
Observations between consecutive test set starts. None means equal to steps. |
skip_folds |
int, list of int, None
|
Folds to skip. Int means keep every n-th fold; list specifies indexes. |
allow_incomplete_fold |
bool
|
Whether to allow a final fold with fewer observations than steps. |
reasoning |
str
|
Explanation of why these parameters were chosen. Shown to the user for transparency. |
Attributes¶
initial_train_size
class-attribute
instance-attribute
¶
initial_train_size = Field(
description="Number of observations (int), fraction of the data (float in (0, 1)), or, only when the dataset context lists a date range, an ISO date string ('YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS') strictly inside that range marking the end of the initial training set."
)
refit
class-attribute
instance-attribute
¶
refit = Field(
default=False,
description="Whether to refit the model every fold (True), never (False, train once), or every n folds (int). Refitting multiplies the training cost by the number of folds.",
)
fixed_train_size
class-attribute
instance-attribute
¶
fixed_train_size = Field(
default=False,
description="If True, training window stays fixed (rolling). If False, training window expands each fold.",
)
gap
class-attribute
instance-attribute
¶
gap = Field(
default=0,
ge=0,
description="Number of observations between training end and test start.",
)
fold_stride
class-attribute
instance-attribute
¶
fold_stride = Field(
default=None,
ge=1,
description="Number of observations between consecutive test set starts. None defaults to steps (non-overlapping test sets).",
)
skip_folds
class-attribute
instance-attribute
¶
skip_folds = Field(
default=None,
description="Folds to skip. Int keeps every n-th fold; list specifies fold indexes to skip.",
)
allow_incomplete_fold
class-attribute
instance-attribute
¶
allow_incomplete_fold = Field(
default=True,
description="Whether to allow a final fold with fewer observations than steps.",
)
reasoning
class-attribute
instance-attribute
¶
reasoning = Field(
description="Explanation of why these parameters were chosen, referencing the user's deployment scenario."
)
PreprocessingStep ¶
Bases: BaseModel
A preprocessing action required before forecasting.
Attributes:
| Name | Type | Description |
|---|---|---|
action |
str
|
Identifier for the preprocessing operation (e.g.
|
reason |
str
|
Human-readable explanation of why this step is needed. |
code_snippet |
str
|
Python code template that implements this step. The snippet of a
blocking step must be one of the templates |
blocking |
bool, default True
|
Whether skforecast will fail without this step. Blocking steps are emitted into the generated script; non-blocking steps are informational and never emitted. |
WindowFeature ¶
Bases: BaseModel
A single rolling-window feature specification for a forecaster.
Attributes:
| Name | Type | Description |
|---|---|---|
stats |
list of str
|
Rolling statistics to compute (e.g. |
window_size |
int
|
Rolling window length in observations, applied to every statistic
in |
Attributes¶
stats
class-attribute
instance-attribute
¶
stats = Field(
description="Rolling statistics to compute. Each value must be one of: 'mean', 'std', 'min', 'max', 'sum', 'median', 'ratio_min_max', 'coef_variation', 'ewm'."
)
window_size
class-attribute
instance-attribute
¶
window_size = Field(
gt=0,
strict=True,
description="Rolling window length in observations, e.g. 7. Must be a positive integer. Scalar only: it is applied to every statistic in `stats`. Use one entry per window size to combine several sizes.",
)
PlanOverrides ¶
Bases: BaseModel
LLM-produced overrides for a forecasting plan.
The field constraints mirror _validate_lags and
_validate_window_features, the checks plan() applies to explicit
overrides, so an invalid suggestion fails at the schema boundary and
pydantic-ai sends the error back to the model before the refinement
loop sees it.
Attributes:
| Name | Type | Description |
|---|---|---|
lags |
list of int, int, default None
|
Overridden lag indices (non-empty list of unique positive ints) or
lag count (positive int meaning lags |
window_features |
list of WindowFeature, default None
|
Overridden window features configurations. The same statistic cannot be paired with the same window size in two entries. |
reasoning |
str
|
Explanation of why the LLM chose these features based on the user's domain knowledge prompt. |
Attributes¶
lags
class-attribute
instance-attribute
¶
lags = Field(
default=None,
description="The lag indices to use for the forecaster: a non-empty list of unique positive integers, e.g. [1, 2, 3, 7, 14], or a single positive integer n for the consecutive lags 1..n.",
)
window_features
class-attribute
instance-attribute
¶
window_features = Field(
default=None,
description="The window features configurations to use. E.g. [{'stats': ['mean', 'std'], 'window_size': 7}]. Do not repeat the same statistic with the same window size in two entries.",
)
reasoning
class-attribute
instance-attribute
¶
reasoning = Field(
description="Explanation of why these specific features (lags and window features) were chosen based on the user's prompt and time series context."
)
RefinePlanOverrides ¶
Bases: TypedDict
Keyword overrides accepted by ForecastingAssistant.refine_plan().
Every key is optional, and what matters is whether a key is present:
an omitted key keeps the value of the plan being refined, while a key
passed as None asks for the deterministic default. The dictionary is
a typing aid (editors autocomplete the keys and type checkers reject
unknown ones); refine_plan() validates the keys at run time as well.
Attributes:
| Name | Type | Description |
|---|---|---|
forecaster |
str
|
Forecaster class name, e.g. |
estimator |
str
|
Estimator class name, e.g. |
estimator_kwargs |
(dict, None)
|
Keyword arguments for the estimator constructor. None resets them to the built-in defaults. |
steps |
int
|
Forecast horizon. |
interval |
list of float, None
|
Prediction interval quantiles as |
lags |
int, list of int, None
|
Lag configuration: a positive int (consecutive lags |
window_features |
list of dict, None
|
Rolling window features, one dict with |
metric |
str, list of str, None
|
Metric(s) to compute, the first one being the primary metric, as
in |
use_exog |
(bool, None)
|
Whether the plan uses the exogenous variables, as in |
differentiation |
(int, None)
|
Order of differencing of the target, as in |
calendar_features |
list of str, None
|
Calendar features to generate, as in |
target_transformer |
(str, None)
|
|
dropna_from_series |
(bool, None)
|
Whether to drop the training rows with missing values, as in
|
Attributes¶
CandidateConfig ¶
Bases: TypedDict
Configuration of one candidate in ForecastingAssistant.compare().
The keys mirror the overrides plan() accepts for a candidate. Every
key is optional; an omitted key keeps the profile recommendation. The
dictionary is a typing aid; compare() validates the keys at run time
as well.
Attributes:
| Name | Type | Description |
|---|---|---|
forecaster |
str
|
Forecaster class name, e.g. |
estimator |
str
|
Estimator class name, e.g. |
estimator_kwargs |
(dict, None)
|
Keyword arguments for the estimator constructor. |
lags |
int, list of int, None
|
Lag configuration: a positive int (consecutive lags |
window_features |
list of dict, None
|
Rolling window features, one dict with |
use_exog |
(bool, None)
|
Whether the candidate uses the exogenous variables, as in |
differentiation |
(int, None)
|
Order of differencing of the target, as in |
calendar_features |
list of str, None
|
Calendar features to generate, as in |
target_transformer |
(str, None)
|
|
dropna_from_series |
(bool, None)
|
Whether to drop the training rows with missing values, as in
|
Attributes¶
ForecastPlan ¶
Bases: PickleDefaultsMixin, DisplayMixin, BaseModel
Detailed forecasting plan produced from a ForecastingProfile.
Carries every concrete decision needed to fit, evaluate and predict: lag structure, prediction intervals, NaN handling, exogenous usage and preprocessing steps.
Attributes:
| Name | Type | Description |
|---|---|---|
task_type |
str
|
Forecasting task category (mirrored from the source
|
forecaster |
str
|
Name of the skforecast forecaster class. It must be a supported
forecaster whose task type is |
forecaster_kwargs |
dict, default {}
|
Keyword arguments for the forecaster constructor (e.g. |
estimator |
str, default None
|
Name of the scikit-learn compatible estimator. For |
estimator_kwargs |
dict, default {}
|
Keyword arguments for the estimator constructor (e.g.
|
steps |
int
|
Number of steps ahead to predict: an integer of at least 1. An
integral float ( |
frequency |
str, default None
|
Pandas frequency string for the series. |
end_train |
str, default None
|
Last datetime (inclusive) of the training set as a string
(e.g. |
interval |
list, default None
|
Prediction interval quantiles as |
interval_method |
str, default None
|
Method for prediction intervals. One of |
metric |
str, default 'mean_absolute_error'
|
Recommended primary evaluation metric (string name matching sklearn/skforecast naming conventions). |
metrics_to_compute |
(list, default['mean_absolute_error', 'mean_squared_error', 'mean_absolute_scaled_error'])
|
Full list of metrics to evaluate in generated code. |
use_exog |
bool, default False
|
Whether to include exogenous variables. |
preprocessing_steps |
list
|
Ordered list of preprocessing steps required before forecasting.
A blocking step is written into the script, so its action and
snippet must be one of those |
warnings |
list
|
Text of the warnings that |
llm_refined_fields |
list
|
Names of the fields ( |
overridden_fields |
list
|
Names of the decisions the user made instead of the rules of
|
exog_columns |
list, default None
|
Exogenous columns of the profile the plan was built from, when that
profile left columns of the data out ( |
explanation |
str
|
Explanation of the plan-level decisions. |
Attributes¶
forecaster_kwargs
class-attribute
instance-attribute
¶
forecaster_kwargs = Field(default_factory=dict)
estimator_kwargs
class-attribute
instance-attribute
¶
estimator_kwargs = Field(default_factory=dict)
metrics_to_compute
class-attribute
instance-attribute
¶
metrics_to_compute = Field(
default_factory=lambda: [
"mean_absolute_error",
"mean_squared_error",
"mean_absolute_scaled_error",
]
)
preprocessing_steps
class-attribute
instance-attribute
¶
preprocessing_steps = Field(default_factory=list)
llm_refined_fields
class-attribute
instance-attribute
¶
llm_refined_fields = Field(default_factory=list)
overridden_fields
class-attribute
instance-attribute
¶
overridden_fields = Field(default_factory=list)