Agentic forecasting step-by-step¶
skforecast-ai is an AI forecasting assistant that pairs a deterministic engine, powered by skforecast, with an LLM reasoning layer. Simply provide a time series, and the assistant automatically profiles the data, selects a model using established best practices, and evaluates its performance. It returns both the final forecast and the runnable skforecast script that produced it.
This tutorial walks through the step-by-step path: the approach for users who want granular control to inspect or adjust intermediate decisions before committing to a full run. If you prefer a single-call workflow that returns results immediately, see the fast-path tutorial.
Both paths share the same deterministic engine and produce identical results and reproducible skforecast code. The step-by-step path gives you three additional capabilities:
Inspect intermediate objects: examine the
ForecastingProfileandForecastPlanbefore any model is trained, and confirm the assistant's recommendations make sense for your domain.Override any single decision: change the forecaster, the estimator and its hyperparameters, the lags, the window features, the horizon or the interval without re-running the entire pipeline from scratch. Pass the modified plan directly to
forecast()orbacktest().Reuse the profile and plan across branches: build the profile and plan once, then run
forecast()for future predictions,backtest()for historical evaluation, andcompare()to rank several candidate configurations: each reusing the same profile, with no redundant profiling.
The ask() method is available at every stage. It interprets what you pass to it (a profile, a plan, a generated script, a cross-validation strategy, a forecast result, a backtest result, or a comparison result), but it never executes the workflow or silently changes any recommendation.
The following example walks through the step-by-step path, allowing users to understand and control what happens under the hood. If you prefer the quickest way to go from raw data to a validated forecast with minimal setup, visit the fast-path tutorial.
Assistant initialization¶
The first step is to instantiate a ForecastingAssistant, which will be responsible for executing the entire workflow (profiling, planning, backtesting, and forecasting), as well as explaining the outputs and suggesting improvements.
To activate the optional LLM support, users must pass a string in the format 'provider:model_name' (for example, 'openai:gpt-5.5', 'google:gemini-3.8-flash', 'anthropic:claude-sonnet-5-5', or 'ollama:qwen3:8b'). For hosted providers, the corresponding API key must be available as an environment variable or passed explicitly when creating the assistant. Your dataset is never sent: the LLM receives only metadata and summary statistics, never the raw time series values. In this tutorial, we keep send_data_to_llm=False (the default), so passing a result to ask(), whose own predictions and metrics are sent, emits a DataSentToLLMWarning as a reminder.
# Data processing
# ==============================================================================
import os
import pandas as pd
from skforecast.datasets import fetch_dataset
# Plots
# ==============================================================================
import matplotlib.pyplot as plt
import plotly.graph_objects as go
import plotly.io as pio
import plotly.offline as poff
pio.templates.default = "seaborn"
poff.init_notebook_mode(connected=True)
plt.style.use('seaborn-v0_8-darkgrid')
# skforecast and skforecast-ai
# ==============================================================================
import skforecast
import skforecast_ai
from skforecast_ai import ForecastingAssistant
from skforecast.model_selection import TimeSeriesFold
from skforecast.plot import set_dark_theme
# Python utilities
# ==============================================================================
import textwrap
color = '\033[1m\033[38;5;208m'
print(f"{color}Version skforecast_ai: {skforecast_ai.__version__}")
print(f"{color}Version skforecast: {skforecast.__version__}")
Version skforecast_ai: 0.5.0 Version skforecast: 0.27.0
āļø Note
If you do not have access to an LLM, you can still follow the full tutorial using only the deterministic methods. Profiling, planning, backtesting, and forecasting all run without an LLM. Only the ask() explanations and the LLM-guided variants of refine_plan() and create_cv() require a configured LLM; their deterministic counterparts work without one.
# LLM-enabled assistant
# ==============================================================================
LLM_MODEL = "anthropic:claude-sonnet-5-5"
api_key = os.getenv("ANTHROPIC_API_KEY")
assistant = ForecastingAssistant(
llm=LLM_MODEL, api_key=api_key, send_data_to_llm=False
)
# Using AWS Bedrock
# ==============================================================================
# assistant = ForecastingAssistant(
# llm='bedrock:eu.anthropic.claude-sonnet-4-6',
# base_url="eu-west-1"
# )
# Assistant without LLM (deterministic only)
# ==============================================================================
# assistant = ForecastingAssistant()
Before going on, check_llm() reports how the configuration resolves (provider, credentials, endpoint, installed extras) without calling the model, so a missing key shows up here instead of in the first ask(). See Configuring the LLM for the details.
# Check the LLM configuration
# ==============================================================================
assistant.check_llm()
LLM Configuration Check āāāāāāāāāāāāāāāā³āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā Check ā Value ā ā”āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā© ā Status ā ok ā āāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Provider ā anthropic ā āāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Model ā claude-sonnet-5-5 ā āāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Credentials ā explicit api_key ā ā ā Explicit api_key given; the environment is not consulted. ā āāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Base URL ā None ā āāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Dependencies ā installed ā āāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Test call ā skipped ā āāāāāāāāāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā ļø Your data stays private
Enabling an LLM never sends your time-series data to the model provider.
The assistant passes only a summary of the dataset (frequency, date range, target statistics,
missing values, significant lags) and the forecaster configuration, never the raw observations.
Results passed to ask() are the exception: their own predictions and metrics are
sent, because a question about a result cannot be answered from summary statistics alone, and a
DataSentToLLMWarning reminds you of it. Pass send_data_to_llm=True to
acknowledge it and silence the warning. See
What is sent to the LLM for the full list.
Data¶
The data used in this tutorial represent the hourly usage of the bike share system in the city of Washington, D.C. during the years 2011 and 2012. In addition to the number of users per hour, information about weather conditions and holidays is available.
# Downloading data
# ==============================================================================
data = fetch_dataset('bike_sharing', raw=True)
data = data[['date_time', 'users', 'holiday', 'weather', 'temp']]
data['date_time'] = pd.to_datetime(data['date_time'])
data.head()
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā bike_sharing āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā® ā Description: ā ā Hourly usage of the bike share system in the city of Washington D.C. during the years 2011 and 2012. In ā ā addition to the number of users per hour, information about weather conditions and holidays is available. ā ā ā ā Source: ā ā Fanaee-T,Hadi. (2013). Bike Sharing Dataset. UCI Machine Learning Repository. https://doi.org/10.24432/C5W894. ā ā ā ā URL: ā ā https://raw.githubusercontent.com/skforecast/skforecast-datasets/main/data/bike_sharing_dataset_clean.csv ā ā ā ā Shape: 17544 rows x 12 columns ā ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāÆ
| date_time | users | holiday | weather | temp | |
|---|---|---|---|---|---|
| 0 | 2011-01-01 00:00:00 | 16.0 | 0.0 | clear | 9.84 |
| 1 | 2011-01-01 01:00:00 | 40.0 | 0.0 | clear | 9.02 |
| 2 | 2011-01-01 02:00:00 | 32.0 | 0.0 | clear | 9.02 |
| 3 | 2011-01-01 03:00:00 | 13.0 | 0.0 | clear | 9.84 |
| 4 | 2011-01-01 04:00:00 | 1.0 | 0.0 | clear | 9.84 |
āļø Note
skforecast-ai is ready to preprocess the data, but it is recommended that users apply their own preprocessing steps before using the assistant. This ensures the data is in the desired format and any necessary transformations have been applied before proceeding with the forecasting workflow.
# Interactive plot of time series
# ==============================================================================
fig = go.Figure()
fig.add_trace(
go.Scatter(x=data['date_time'], y=data['users'], mode='lines', name='Users')
)
fig.update_layout(
title = 'Number of users',
xaxis_title="Time",
yaxis_title="Users",
width=800,
height=400,
margin=dict(l=20, r=20, t=35, b=20),
legend=dict(orientation="h", yanchor="top", y=1, xanchor="left", x=0.001)
)
fig.show()
For a deeper walkthrough of the exploratory analysis behind this dataset, see the skforecast example: Forecasting time series with skforecast, XGBoost, LightGBM and CatBoost.
Profile the data¶
The profile() method is the first stage of the step-by-step workflow. It inspects the dataset and returns a ForecastingProfile object that contains:
Data metadata: detected frequency, index type, series lengths, missing values, and exogenous column roles.
Modeling recommendations: the selected forecaster family and estimator, along with alternative candidates and the reasoning behind each choice.
Lag structure: PACF-significant lags per series, used as a baseline for the planning stage.
Window feature suggestions: rolling statistics configurations appropriate for the seasonal periods implied by the frequency.
This is a purely deterministic step: no LLM is involved. The profile object is a prerequisite for plan(), and can be passed to ask() as context to have its decisions explained.
| Attribute | Description |
|---|---|
data_profile |
Full dataset metadata: frequency, index type, series lengths, missing values, exog columns |
task_type |
Family of the recommendation: 'single_series', 'multi_series', 'multivariate', 'statistical' or 'foundation' |
forecaster |
Recommended skforecast forecaster class name |
forecaster_candidates |
Ordered list of compatible forecaster names |
estimator |
Recommended estimator: a scikit-learn compatible estimator name, 'Arima' for statistical tasks, or the Hugging Face model ID of the foundation model |
estimator_candidates |
Ordered list of compatible estimator names |
series_pacf |
Per-series PACF-significant lags (used by plan() to set default lags) |
window_features |
Suggested window feature configurations |
calendar_features |
Recommended calendar feature names derived from the frequency |
explanation |
Human-readable explanation of why this forecaster and estimator were selected |
# Profile the data
# ==============================================================================
profile = assistant.profile(
data = data,
target = 'users',
date_column = 'date_time'
)
# Inspect the profile
# ==============================================================================
profile
Dataset Profile āāāāāāāāāāāāāāāāāā³āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā Property ā Value ā ā”āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā© ā Format ā single ā āāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Series ā 1 ā āāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Observations ā 17544 ā āāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Frequency ā h ā āāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Target ā users ā āāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Exog columns ā holiday, weather, temp (categorical: weather) ā āāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Missing values ā None ā āāāāāāāāāāāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Recommendation āāāāāāāāāāāāāāāāāāāāāāāāā³āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā Property ā Value ā ā”āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā© ā Task type ā single_series ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Forecaster ā ForecasterRecursive ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Forecaster candidates ā ForecasterRecursive, ForecasterDirect, ForecasterFoundation ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Estimator ā LGBMRegressor ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Estimator candidates ā LGBMRegressor, XGBRegressor, Ridge ā āāāāāāāāāāāāāāāāāāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Profile Explanation āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā® ā ā ā A single-series ML forecaster (ForecasterRecursive) is recommended. Data: 17544 ā ā observations, 'h' frequency. Alternative forecasters: ['ForecasterDirect', ā ā 'ForecasterFoundation']. Estimator: LGBMRegressor. A gradient boosting model is ā ā preferred for a dataset of this size (17544 observations). Alternative estimators: ā ā ['XGBRegressor', 'Ridge']. 3 exogenous variables (1 categorical) available as ā ā predictors. ā ā ā ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāÆ
Every result also has a describe() method. It returns a plain-text description of the object, built by rules, without calling an LLM. It is also what ask() sends to the LLM about that object, so you can read it before asking.
# Plain-text description of the profile (no LLM involved)
# ==============================================================================
print(profile.describe())
<forecast_context> <dataset> - Observations: 17544 - Series: 1 - Frequency: h - Date range: 2011-01-01 to 2012-12-31 23:00:00 - Target: users - Exogenous columns: holiday, weather, temp - Categorical exogenous columns: weather - Target statistics: min 1, max 977, mean 187.8, std 181.3 - Missing values: none - Index irregularities: none detected </dataset> <profile_decision> A single-series ML forecaster (ForecasterRecursive) is recommended. Data: 17544 observations, 'h' frequency. Alternative forecasters: ['ForecasterDirect', 'ForecasterFoundation']. Estimator: LGBMRegressor. A gradient boosting model is preferred for a dataset of this size (17544 observations). Alternative estimators: ['XGBRegressor', 'Ridge']. 3 exogenous variables (1 categorical) available as predictors. - Significant lags (partial autocorrelation, strongest first): 1, 2, 23, 22, 25, 169, 10, 145, 17, 143, 167, 19, 21, 337, 3 (first 15 of 32) - Suggested window features: mean(window=3), std(window=3), mean(window=24), mean(window=168) - Suggested calendar features: hour, day_of_week, weekend, month </profile_decision> </forecast_context>
Once you have a profile, you can pass it to ask() as context to get an LLM-generated explanation of the modeling decisions. No plan is involved yet: the LLM only sees the dataset summary and the profile decisions.
Each call briefs the model with a set of skills, curated skforecast documents chosen from the context and the wording of the question, so the answer follows the current skforecast API. See Skills for the LLM for the list and how to choose them yourself.
# Ask the assistant to explain the profile
# ==============================================================================
answer = assistant.ask(
prompt = (
"Explain why this forecaster and estimator were recommended for my "
"hourly bike-sharing demand data, and what the exogenous variables add."
),
context = profile,
)
answer.show_explanation()
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Assistant Response āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā® ā ā ā ForecasterRecursive was recommended because the data is a single hourly series, and ā ā LGBMRegressor was chosen because the profile prefers a gradient boosting model for a ā ā dataset of this size (17544 observations). The three exogenous variables (holiday, ā ā weather, temp) are made available to the model as predictors. No results in the ā ā context show how much they improve accuracy. ā ā ā ā Why ForecasterRecursive ā ā ā ā ⢠The data has 1 series (target: users) at 'h' frequency, which the profile maps to ā ā a single-series ML forecaster. ā ā ⢠The skforecast documentation describes ForecasterRecursive as the general-purpose ā ā default for one series. It works with any sklearn-compatible estimator and ā ā supports lags, window features and exogenous variables, all of which this plan ā ā uses. ā ā ⢠The profile lists ForecasterDirect and ForecasterFoundation as alternatives. It ā ā gives no further reasoning for them, so I can't say more about why they ranked ā ā behind the recommendation. ā ā ā ā Why LGBMRegressor ā ā ā ā ⢠The profile states that a gradient boosting model is preferred for a dataset of ā ā this size. That is the only stated reason. ā ā ⢠XGBRegressor and Ridge are listed as alternative estimators. As with the ā ā forecasters, the context does not explain the ordering beyond that. ā ā ⢠The estimator and lags are set by deterministic code, so I report them as given. ā ā ā ā What the exogenous variables add ā ā ā ā ⢠Three exogenous columns are available: holiday, weather and temp. Of these, ā ā weather is categorical. ā ā ⢠They give the model information beyond the target's own history, which enters ā ā through the lags and window features. The plan suggests lags such as 1, 2, 23, ā ā 22, 25 and 169, plus rolling mean and std windows. ā ā ⢠The profile also suggests calendar features: hour, day_of_week, weekend and ā ā month. ā ā ⢠For forecasting, the documentation notes that exogenous values must be supplied ā ā for every future step in the horizon. ā ā ā ā What I can't tell you ā ā ā ā ⢠No feature importances are provided, so I can't say which lags, window features, ā ā calendar features or exogenous variables contribute most. ā ā ⢠No backtesting metrics or comparison results are in the context, so I can't say ā ā how much the exogenous variables improve accuracy over a model without them. ā ā ā ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāÆ
Build the plan¶
The plan() method converts the coarse modeling decisions in the ForecastingProfile into a fully-specified, executable configuration. It determines:
- Lags: derived from the PACF-significant lags detected in the profile. You can override these explicitly.
- Window features: rolling statistics configurations appropriate for the seasonal periods implied by the frequency.
- Preprocessing steps: ordered list of data preparation actions (e.g., handling missing values, gaps or categorical exogenous variables).
- Prediction interval method:
'bootstrapping','conformal', or'native'(selected based on the forecaster). - Metrics: the primary and secondary evaluation metrics.
Like profile(), this is a deterministic step. The resulting ForecastPlan object is the complete blueprint that forecast() and backtest() execute.
| Attribute | Description |
|---|---|
task_type |
Family of the plan, as in the profile, plus 'baseline' for ForecasterEquivalentDate |
forecaster |
Forecaster class name |
estimator |
Estimator class name; the Hugging Face model ID for ForecasterFoundation; None for ForecasterEquivalentDate |
forecaster_kwargs |
All constructor kwargs for the forecaster, including lags and window_features |
estimator_kwargs |
Constructor kwargs for the estimator |
steps |
Forecast horizon |
interval |
Prediction interval quantiles, e.g. [0.1, 0.9] |
interval_method |
Method used to produce the interval (bootstrapping, conformal, or native) |
metric |
Primary metric, used to rank a comparison |
use_exog |
Whether exogenous variables are included |
overridden_fields |
Decisions you made instead of the rules; empty when every value comes from the rules |
preprocessing_steps |
Ordered list of preprocessing actions with code snippets |
explanation |
Human-readable explanation of plan decisions |
# Build a plan from the profile
# ==============================================================================
plan = assistant.plan(
profile = profile,
steps = 36,
interval = [0.1, 0.9] # 80% prediction interval
)
# Inspect the plan
# ==============================================================================
plan
Forecast Plan āāāāāāāāāāāāāāāāāāāāā³āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā Property ā Value ā ā”āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā© ā Task type ā single_series ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Forecaster ā ForecasterRecursive ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Estimator ā LGBMRegressor ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Steps ā 36 ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Frequency ā h ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Lags ā [1, 2, 3, 5, 8, 10, 15, 17, 19, 20, 21, 22, 23, 24, 25, 26, 32, ā ā ā 33, 119, 121, 135, 136, 142, 143, 145, 160, 166, 167, 169, 313, ā ā ā 335, 337] ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Window features ā [{'stats': ['mean', 'std'], 'window_size': 3}, {'stats': ['mean'], ā ā ā 'window_size': 24}, {'stats': ['mean'], 'window_size': 168}] ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Calendar features ā ['hour', 'day_of_week', 'weekend', 'month'] (raw ordinal encoding) ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Use exog ā True ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Interval ā [0.1, 0.9] ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Interval method ā bootstrapping ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Primary metric ā mean_absolute_error ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Preprocessing ā 1 step ā āāāāāāāāāāāāāāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Preprocessing Steps āāāāāāāāāāāāāāāāāāāāāāāāāāā³āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā Step ā Reason ā ā”āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā© ā handle_categorical_exog ā Categorical exogenous variables detected: ['weather']. These ā ā ā are handled automatically by skforecast ā ā ā (categorical_features='auto'). ā āāāāāāāāāāāāāāāāāāāāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Plan Explanation āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā® ā ā ā Plan: ForecasterRecursive + LGBMRegressor. Lags: [1, 2, 3, 5, 8, 10, 15, 17, 19, 20, ā ā 21, 22, 23, 24, 25, 26, 32, 33, 119, 121, 135, 136, 142, 143, 145, 160, 166, 167, ā ā 169, 313, 335, 337]. Window features: ['mean(window=3)', 'std(window=3)', ā ā 'mean(window=24)', 'mean(window=168)']. Calendar features: ['hour', 'day_of_week', ā ā 'weekend', 'month'] (raw ordinal encoding). Prediction intervals via bootstrapping. ā ā Exogenous variables included. MAE is interpretable, robust to outliers, and works at ā ā any scale. ā ā ā ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāÆ
Pass the profile as context together with the plan for a detailed explanation of the chosen configuration. The two are rendered into the same script forecast_code() would produce: answer.code returns it, and the LLM receives a description of it (never the script itself).
# Ask the assistant to explain the plan
# ==============================================================================
answer = assistant.ask(
prompt = (
"Walk me through this plan. Why these lags and window features, "
"and how will the 80% prediction interval be produced?"
),
context = profile,
plan = plan,
)
answer.show_explanation()
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Assistant Response āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā® ā ā ā The plan trains one LGBMRegressor inside a ForecasterRecursive on the hourly users ā ā series and forecasts 36 steps ahead. The lags and window features come from the ā ā profiling step (partial autocorrelation and the suggested window features), and the ā ā 80% interval is produced by bootstrapping. No predictions or metrics exist yet, ā ā because the script has not been run. ā ā ā ā Why these lags ā ā ā ā ⢠The profile ranked significant lags by partial autocorrelation, strongest first: ā ā 1, 2, 23, 22, 25, 169, 10, 145, 17, 143, 167, 19, 21, 337, 3. It reports 32 ā ā significant lags in total, and only the first 15 are shown. ā ā ⢠The plan's lag list has 32 entries: [1, 2, 3, 5, 8, 10, 15, 17, 19, 20, 21, 22, ā ā 23, 24, 25, 26, 32, 33, 119, 121, 135, 136, 142, 143, 145, 160, 166, 167, 169, ā ā 313, 335, 337]. It is the deterministic code's selection. I am reporting it as ā ā given, not re-deriving it. ā ā ⢠I can't say how much each lag contributes to accuracy, because feature ā ā importances are not provided. ā ā ā ā Window features ā ā ā ā ⢠The plan uses four window statistics: mean and std over a window of 3, mean over ā ā 24, and mean over 168. They match the suggested window features in the profile. ā ā ⢠A window of 24 and a window of 168 correspond to one day and one week at hourly ā ā frequency. ā ā ⢠Window features are computed on the series as the forecaster sees it. The plan ā ā does not mention differentiation, so I won't comment on its interaction with ā ā them. ā ā ā ā Other predictors ā ā ā ā ⢠Exogenous variables: holiday, weather, and temp. weather is categorical and is ā ā handled automatically (categorical_features='auto'). ā ā ⢠Calendar features: hour, day_of_week, weekend, and month, with raw ordinal ā ā encoding. ā ā ⢠The script reads exog_future.csv. The exogenous values must cover every one of ā ā the 36 forecast steps. I can't validate that file's contents from the context. ā ā ā ā How the 80% interval is produced ā ā ā ā ⢠The interval is set to [0.1, 0.9], which gives 80% nominal coverage, using the ā ā bootstrapping method. ā ā ⢠In skforecast, bootstrapping draws from the model's stored residuals to simulate ā ā many possible future paths. The interval bounds are taken as quantiles of those ā ā simulated paths. ā ā ⢠Residuals must be stored at fit time (store_in_sample_residuals=True) for this to ā ā work on a standalone forecaster. I can't confirm from the script summary that it ā ā does this, so check it before running. ā ā ⢠The plan does not give the number of bootstrap repetitions, so I can't state it. ā ā ⢠"80% nominal" is the intended coverage. Actual coverage has not been measured, ā ā and no backtest results are available. ā ā ā ā Next steps ā ā ā ā ⢠assistant.backtest() would measure the MAE (the plan's primary metric) of this ā ā configuration on held-out data. ā ā ⢠assistant.compare() would help choose between this setup and the alternatives ā ā named in the profile (ForecasterDirect, ForecasterFoundation, XGBRegressor, ā ā Ridge). ā ā ⢠assistant.forecast() runs the script and returns the predictions. ā ā ā ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāÆ
Refine the plan (optional)¶
The refine_plan() method lets you adjust the plan before execution. It operates in two distinct modes:
Deterministic mode (
prompt=None): pass explicit configuration overrides such aslags,estimator,estimator_kwargs,forecaster,steps,interval, orwindow_features. Only the fields you explicitly specify are updated; the rest of the configuration is deterministically re-derived from the original plan.LLM mode (
promptprovided): describe your domain knowledge in natural language. The LLM interprets this context and suggests appropriatelagsandwindow_features. Its reasoning is appended toplan.explanationand the changed fields are recorded inplan.llm_refined_fieldsfor full traceability. It applies to the machine learning forecasters:ForecasterStats,ForecasterFoundationandForecasterEquivalentDateuse no lags or window features, so for them the prompt is ignored with a warning and the LLM is not called.
The Agentic forecasting guide shows in an animation what the LLM receives in LLM mode, and how a suggestion is validated before it enters the plan.
ā Warning
A refined plan is a hypothesis, not a guaranteed improvement. The LLM may propose lags or window features that are not helpful for the series, or it may misread the domain context you provided. Always compare the refined plan against the original baseline using a proper backtest over multiple folds before adopting it.
Deterministic mode¶
# Refine the plan with explicit overrides (no LLM required)
# ==============================================================================
plan_det = assistant.refine_plan(
profile = profile,
plan = plan,
lags = [1, 2, 3, 24, 48, 168],
estimator_kwargs = {'n_estimators': 200, 'max_depth': 6},
metric = 'mean_absolute_scaled_error'
)
plan_det
Forecast Plan āāāāāāāāāāāāāāāāāāāāā³āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā Property ā Value ā ā”āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā© ā Task type ā single_series ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Forecaster ā ForecasterRecursive ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Estimator ā LGBMRegressor ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Steps ā 36 ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Frequency ā h ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Lags ā [1, 2, 3, 24, 48, 168] ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Window features ā [{'stats': ['mean', 'std'], 'window_size': 3}, {'stats': ['mean'], ā ā ā 'window_size': 24}, {'stats': ['mean'], 'window_size': 168}] ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Calendar features ā ['hour', 'day_of_week', 'weekend', 'month'] (raw ordinal encoding) ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Use exog ā True ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Interval ā [0.1, 0.9] ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Interval method ā bootstrapping ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Primary metric ā mean_absolute_scaled_error ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Preprocessing ā 1 step ā āāāāāāāāāāāāāāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Preprocessing Steps āāāāāāāāāāāāāāāāāāāāāāāāāāā³āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā Step ā Reason ā ā”āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā© ā handle_categorical_exog ā Categorical exogenous variables detected: ['weather']. These ā ā ā are handled automatically by skforecast ā ā ā (categorical_features='auto'). ā āāāāāāāāāāāāāāāāāāāāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Plan Explanation āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā® ā ā ā Plan: ForecasterRecursive + LGBMRegressor. Lags: [1, 2, 3, 24, 48, 168]. Window ā ā features: ['mean(window=3)', 'std(window=3)', 'mean(window=24)', ā ā 'mean(window=168)']. Calendar features: ['hour', 'day_of_week', 'weekend', 'month'] ā ā (raw ordinal encoding). Prediction intervals via bootstrapping. Exogenous variables ā ā included. Metric: mean_absolute_scaled_error, as requested. ā ā ā ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāÆ
metric is one of the arguments that choose a decision instead of the rule. The others are use_exog, differentiation, calendar_features, target_transformer and dropna_from_series, and plan() accepts them too. overridden_fields names the decisions you made, so the plan always tells your choices from the ones of the rules.
# Decisions made by the user instead of the rules
# ==============================================================================
plan_det.overridden_fields
['estimator_kwargs', 'lags', 'metric']
LLM mode¶
# Refine the plan using LLM-guided domain knowledge
# ==============================================================================
prompt = (
"I'm forecasting hourly bike rentals. Demand follows a clear daily rhythm with "
"rush-hour peaks, and it changes between weekdays and weekends. It's also usually "
"similar to what happened at the same time last week, and the last few hours give "
"a good sense of the current trend. Please pick lags and rolling features that fit this."
)
plan_refined = assistant.refine_plan(
profile = profile,
plan = plan,
prompt = prompt
)
# Refined plan proposed by the assistant
# ==============================================================================
plan_refined
Forecast Plan āāāāāāāāāāāāāāāāāāāāā³āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā Property ā Value ā ā”āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā© ā Task type ā single_series ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Forecaster ā ForecasterRecursive ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Estimator ā LGBMRegressor ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Steps ā 36 ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Frequency ā h ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Lags ā [1, 2, 3, 4, 5, 6, 12, 23, 24, 25, 47, 48, 72, 96, 120, 144, 167, ā ā ā 168, 169, 336] (LLM-suggested) ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Window features ā [{'stats': ['mean', 'std'], 'window_size': 3}, {'stats': ['mean', ā ā ā 'std'], 'window_size': 24}, {'stats': ['mean'], 'window_size': ā ā ā 168}] (LLM-suggested) ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Calendar features ā ['hour', 'day_of_week', 'weekend', 'month'] (raw ordinal encoding) ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Use exog ā True ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Interval ā [0.1, 0.9] ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Interval method ā bootstrapping ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Primary metric ā mean_absolute_error ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Preprocessing ā 1 step ā āāāāāāāāāāāāāāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Preprocessing Steps āāāāāāāāāāāāāāāāāāāāāāāāāāā³āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā Step ā Reason ā ā”āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā© ā handle_categorical_exog ā Categorical exogenous variables detected: ['weather']. These ā ā ā are handled automatically by skforecast ā ā ā (categorical_features='auto'). ā āāāāāāāāāāāāāāāāāāāāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Plan Explanation āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā® ā ā ā Plan: ForecasterRecursive + LGBMRegressor. Lags: [1, 2, 3, 4, 5, 6, 12, 23, 24, 25, ā ā 47, 48, 72, 96, 120, 144, 167, 168, 169, 336]. Window features: ['mean(window=3)', ā ā 'std(window=3)', 'mean(window=24)', 'std(window=24)', 'mean(window=168)']. Calendar ā ā features: ['hour', 'day_of_week', 'weekend', 'month'] (raw ordinal encoding). ā ā Prediction intervals via bootstrapping. Exogenous variables included. MAE is ā ā interpretable, robust to outliers, and works at any scale. ā ā ā ā LLM Refinement Reasoning: Short lags 1-6 capture the current trend over the last few ā ā hours. Lags 12, 23, 24 and 25 capture the daily rhythm, so the same hour yesterday ā ā and its neighbours help with the rush-hour peaks. Lags 47, 48, 72, 96, 120 and 144 ā ā give the same hour on earlier days. Lags 167, 168 and 169 capture same hour last ā ā week, which separates weekday from weekend behaviour. Lag 336 adds the same hour two ā ā weeks ago for a more robust weekly reference. This replaces the sparse, irregular ā ā set of lags with a structured one tied to the daily and weekly cycles. Window ā ā features add a short 3-hour mean and std for recent level and volatility, a 24-hour ā ā mean and std for the daily level and variability, and a 168-hour mean for the weekly ā ā level. I kept the set compact to avoid redundant features. ā ā ā ā Note: the LLM-suggested lags and window_features are hypotheses, not validated ā ā improvements. Confirm any expected accuracy gain before relying on them. ā ā ā ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāÆ
Explain mode (refined plan)¶
# Ask the assistant what changed and why
# ==============================================================================
answer = assistant.ask(
prompt = (
"What changed in the refined plan compared to the original, "
"and why does it matter for this dataset?"
),
context = profile,
plan = plan_refined,
)
answer.show_explanation()
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Assistant Response āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā® ā ā ā The refinement replaced the data-driven lag list from the profile with a structured ā ā set of lags tied to daily and weekly cycles, and added one window feature (the ā ā 24-hour standard deviation). Whether this helps on this dataset has not been ā ā measured: the plan states that the refined lags and window features are hypotheses, ā ā not validated improvements. ā ā ā ā Lags ā ā ā ā ⢠The profile ranked significant lags by partial autocorrelation. Only the first 15 ā ā of 32 are shown: 1, 2, 23, 22, 25, 169, 10, 145, 17, 143, 167, 19, 21, 337, 3. I ā ā cannot say how the refined set compares against the 17 lags that are not shown. ā ā ⢠The refined plan uses: 1, 2, 3, 4, 5, 6, 12, 23, 24, 25, 47, 48, 72, 96, 120, ā ā 144, 167, 168, 169, 336. ā ā ⢠Among the visible original lags, 22, 10, 17, 19 and 21 do not appear in the ā ā refined list. Lags 143, 145 and 337 are replaced by 144 and 336 (the neighbouring ā ā lags 167 and 169 are kept, with 168 added). ā ā ⢠The refinement reasoning describes the original as "sparse, irregular" and the ā ā new set as organised around the daily and weekly cycles: short lags for recent ā ā hours, 12 to 25 for the daily rhythm, 47 to 144 for the same hour on earlier ā ā days, 167 to 169 for the same hour last week, and 336 for two weeks ago. ā ā ā ā Window features ā ā ā ā ⢠The profile suggested mean and std over 3 hours, mean over 24 hours, and mean ā ā over 168 hours. ā ā ⢠The refined plan keeps all of these and adds the std over 24 hours. The stated ā ā rationale is to capture daily variability alongside the daily level. ā ā ā ā Unchanged ā ā ā ā ⢠Forecaster (ForecasterRecursive), estimator (LGBMRegressor), the 36-step horizon, ā ā and the bootstrapped 80% interval are the same. ā ā ⢠Calendar features (hour, day_of_week, weekend, month) match the profile ā ā suggestion. ā ā ⢠The three exogenous variables (holiday, weather, temp) are still used, with ā ā weather handled as categorical. ā ā ā ā Why it matters here ā ā ā ā ⢠The hourly data (2011-01-01 to 2012-12-31 23:00:00) is the kind of series where ā ā daily and weekly cycles are plausible, which is the reasoning behind this lag ā ā structure. That is the refinement's rationale, not a measured result. ā ā ⢠I cannot say which lags or window features would contribute to accuracy, since no ā ā feature importances are provided. ā ā ⢠This is a prediction-mode script with no ground truth, so there are no metrics ā ā comparing the original and refined configurations. To measure accuracy, ā ā assistant.backtest() is the relevant call. To choose between the original and ā ā refined configurations, use assistant.compare(). ā ā ā ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāÆ
Forecast¶
Once you have a profile and a plan, you can call forecast() or forecast_code(). Both accept the pre-computed profile and plan so no additional profiling is performed. The forecast() method executes the generated script and returns a ForecastResult; forecast_code() generates the script only, without running it.
The forecast branch operates in two modes:
Evaluation mode (
test_sizeis set): the dataset is split into train and test sets, the model is trained on the train portion, and predictions are compared against the held-out actuals to compute metrics.Prediction mode (
test_size=None, the default): the model is trained on the entire dataset and forecasts the nextstepstime points into the future. Because there is no ground truth, no metrics are returned. If the plan uses exogenous variables, their future values must be supplied viaexog.
Evaluation mode¶
# Forecast in evaluation mode, reusing the pre-computed profile and plan
# ==============================================================================
results_eval = assistant.forecast(
data = data,
steps = 36,
interval = [0.1, 0.9], # 80% prediction interval
test_size = 36, # Last 36 hours as test set
profile = profile, # Reuse the pre-computed profile
plan = plan_refined # Reuse the refined plan
)
display(results_eval.metrics)
display(results_eval.predictions.head())
| mean_absolute_error | root_mean_squared_error | mean_absolute_scaled_error | mean_absolute_percentage_error | |
|---|---|---|---|---|
| 0 | 27.682061 | 41.672254 | 0.429918 | 0.383013 |
| pred | lower_bound | upper_bound | |
|---|---|---|---|
| 2012-12-30 12:00:00 | 140.995418 | 108.753973 | 163.432992 |
| 2012-12-30 13:00:00 | 143.046714 | 100.553352 | 178.592630 |
| 2012-12-30 14:00:00 | 142.311187 | 97.090933 | 177.040944 |
| 2012-12-30 15:00:00 | 155.902904 | 101.702094 | 189.330997 |
| 2012-12-30 16:00:00 | 150.065710 | 104.187007 | 195.469717 |
# Plot predictions vs. actual values for the held-out test period
# ==============================================================================
set_dark_theme()
preds = results_eval.predictions
fig, ax = plt.subplots(figsize=(7, 3.5))
data.set_index('date_time').loc[preds.index, 'users'].plot(ax=ax, label='actual')
preds['pred'].plot(ax=ax, label='prediction')
if {'lower_bound', 'upper_bound'}.issubset(preds.columns):
ax.fill_between(
preds.index, preds['lower_bound'], preds['upper_bound'],
alpha=0.3, label='80% prediction interval'
)
ax.set_title('Predictions vs. actual bike demand')
ax.set_ylabel('Users')
ax.legend()
plt.tight_layout()
plt.show()
# Ask the assistant to interpret the forecast results
# ==============================================================================
answer = assistant.ask(
prompt = "Explain the results of this forecast, including the metrics and predictions.",
context = results_eval
)
answer.show_explanation()
/var/folders/wt/8tvn563d5v55nspfbydgqb9r0000gp/T/ipykernel_87469/3255811032.py:3: DataSentToLLMWarning: `send_data_to_llm=False` does not apply to `context`: the predicted values it carries are sent to the LLM, because a question about a result cannot be answered from summary statistics alone. Your input data is not sent: the observed values that the predictions of a backtest carry (`y_true`) are left out, and a result holds no other value of the data it was fitted on. To keep predictions local, ask without `context`. answer = assistant.ask(
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Assistant Response āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā® ā ā ā The model's hold-out error over the 36 hourly steps is a mean absolute error of ā ā 27.682061 users, and its MASE of 0.429918 is below 1, so it beat the one-step naive ā ā forecast (repeat the previous value) on this window. This is a hold-out evaluation ā ā on dates already in the data, not a forecast of the future. The model was trained up ā ā to 2012-12-30 11:00:00 and scored on the next 36 hours. ā ā ā ā Setup being evaluated ā ā ā ā ⢠ForecasterRecursive with LGBMRegressor, forecasting users 36 steps ahead at ā ā hourly frequency. ā ā ⢠Inputs: 20 lags, rolling mean and std window features, and the exogenous columns ā ā holiday, weather and temp (weather is categorical and handled automatically). ā ā ⢠The lags and window features were suggested by an LLM refinement step. They are ā ā hypotheses, not validated improvements. ā ā ⢠Prediction intervals use bootstrapping with an 80% nominal level (quantiles 0.1 ā ā and 0.9). ā ā ā ā Metrics ā ā ā ā ⢠MAE, 27.682061: the average absolute miss, in units of users. This is the primary ā ā metric for the plan. ā ā ⢠RMSE, 41.672254: also in units of users. It is reported alongside MAE, but I ā ā can't say anything further about the error distribution from these two numbers ā ā alone. ā ā ⢠MASE, 0.429918: below 1, so the model beat the one-step naive forecast on this ā ā window. ā ā ⢠MAPE, 0.383013: a fraction, quoted as given. The target's minimum is 1, so values ā ā near zero make MAPE unreliable here. I would lean on MAE, RMSE and MASE instead. ā ā ā ā Predictions ā ā ā ā Only the first 5 and last 5 of the 36 rows were provided, so I won't describe a ā ā trend across the horizon. Over all 36 rows: ā ā ā ā ⢠Point predictions range from 5.065354 to 208.092608, with a mean of 101.619250. ā ā ⢠The lower bound has a mean of 69.115761 (range 0.320592 to 163.187113). ā ā ⢠The upper bound has a mean of 139.768766 (range 9.997289 to 340.043089). ā ā ā ā Limitations ā ā ā ā ⢠Interval coverage and mean interval width were not supplied, so I can't say ā ā whether the 80% intervals actually contained about 80% of the observed values. ā ā ⢠The metrics come from a single 36-step window. Per-fold spread is not available, ā ā so I can't say how stable these numbers would be on other periods. ā ā ā ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāÆ
Prediction mode¶
In prediction mode, the model trains on the entire dataset and forecasts the next steps time points. Because the data includes exogenous variables (holiday, weather, temp), their future values must be supplied via the exog argument.
# Forecast the next 36 hours using the entire dataset (prediction mode)
# ==============================================================================
# Simulate future values of exogenous variables for the next 36 hours
exog = data[['holiday', 'weather', 'temp']].tail(36).copy()
exog.index = pd.date_range(
start=pd.to_datetime(data['date_time'].max()) + pd.Timedelta(1, unit='h'),
periods=36,
freq='h'
)
results_pred = assistant.forecast(
data = data,
steps = 36,
interval = [0.1, 0.9],
test_size = None, # Use the entire dataset (prediction mode)
exog = exog, # Future values of exogenous variables
profile = profile,
plan = plan_refined
)
display(results_pred.predictions.head())
| pred | lower_bound | upper_bound | |
|---|---|---|---|
| 2013-01-01 00:00:00 | 21.122524 | 13.812877 | 33.172653 |
| 2013-01-01 01:00:00 | 12.348644 | 3.750090 | 26.199809 |
| 2013-01-01 02:00:00 | 9.221664 | 3.831727 | 19.045463 |
| 2013-01-01 03:00:00 | 5.183875 | 0.997964 | 12.502876 |
| 2013-01-01 04:00:00 | 5.351029 | 1.011118 | 11.155282 |
# Full results object
# ==============================================================================
results_pred
Dataset Profile āāāāāāāāāāāāāāāāāā³āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā Property ā Value ā ā”āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā© ā Format ā single ā āāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Series ā 1 ā āāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Observations ā 17544 ā āāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Frequency ā h ā āāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Target ā users ā āāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Exog columns ā holiday, weather, temp (categorical: weather) ā āāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Missing values ā None ā āāāāāāāāāāāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Recommendation āāāāāāāāāāāāāāāāāāāāāāāāā³āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā Property ā Value ā ā”āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā© ā Task type ā single_series ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Forecaster ā ForecasterRecursive ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Forecaster candidates ā ForecasterRecursive, ForecasterDirect, ForecasterFoundation ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Estimator ā LGBMRegressor ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Estimator candidates ā LGBMRegressor, XGBRegressor, Ridge ā āāāāāāāāāāāāāāāāāāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Profile Explanation āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā® ā ā ā A single-series ML forecaster (ForecasterRecursive) is recommended. Data: 17544 ā ā observations, 'h' frequency. Alternative forecasters: ['ForecasterDirect', ā ā 'ForecasterFoundation']. Estimator: LGBMRegressor. A gradient boosting model is ā ā preferred for a dataset of this size (17544 observations). Alternative estimators: ā ā ['XGBRegressor', 'Ridge']. 3 exogenous variables (1 categorical) available as ā ā predictors. ā ā ā ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⯠Forecast Plan āāāāāāāāāāāāāāāāāāāāā³āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā Property ā Value ā ā”āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā© ā Task type ā single_series ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Forecaster ā ForecasterRecursive ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Estimator ā LGBMRegressor ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Steps ā 36 ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Frequency ā h ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Lags ā [1, 2, 3, 4, 5, 6, 12, 23, 24, 25, 47, 48, 72, 96, 120, 144, 167, ā ā ā 168, 169, 336] (LLM-suggested) ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Window features ā [{'stats': ['mean', 'std'], 'window_size': 3}, {'stats': ['mean', ā ā ā 'std'], 'window_size': 24}, {'stats': ['mean'], 'window_size': ā ā ā 168}] (LLM-suggested) ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Calendar features ā ['hour', 'day_of_week', 'weekend', 'month'] (raw ordinal encoding) ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Use exog ā True ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Interval ā [0.1, 0.9] ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Interval method ā bootstrapping ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Primary metric ā mean_absolute_error ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Preprocessing ā 1 step ā āāāāāāāāāāāāāāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Preprocessing Steps āāāāāāāāāāāāāāāāāāāāāāāāāāā³āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā Step ā Reason ā ā”āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā© ā handle_categorical_exog ā Categorical exogenous variables detected: ['weather']. These ā ā ā are handled automatically by skforecast ā ā ā (categorical_features='auto'). ā āāāāāāāāāāāāāāāāāāāāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Plan Explanation āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā® ā ā ā Plan: ForecasterRecursive + LGBMRegressor. Lags: [1, 2, 3, 4, 5, 6, 12, 23, 24, 25, ā ā 47, 48, 72, 96, 120, 144, 167, 168, 169, 336]. Window features: ['mean(window=3)', ā ā 'std(window=3)', 'mean(window=24)', 'std(window=24)', 'mean(window=168)']. Calendar ā ā features: ['hour', 'day_of_week', 'weekend', 'month'] (raw ordinal encoding). ā ā Prediction intervals via bootstrapping. Exogenous variables included. MAE is ā ā interpretable, robust to outliers, and works at any scale. ā ā ā ā LLM Refinement Reasoning: Short lags 1-6 capture the current trend over the last few ā ā hours. Lags 12, 23, 24 and 25 capture the daily rhythm, so the same hour yesterday ā ā and its neighbours help with the rush-hour peaks. Lags 47, 48, 72, 96, 120 and 144 ā ā give the same hour on earlier days. Lags 167, 168 and 169 capture same hour last ā ā week, which separates weekday from weekend behaviour. Lag 336 adds the same hour two ā ā weeks ago for a more robust weekly reference. This replaces the sparse, irregular ā ā set of lags with a structured one tied to the daily and weekly cycles. Window ā ā features add a short 3-hour mean and std for recent level and volatility, a 24-hour ā ā mean and std for the daily level and variability, and a 168-hour mean for the weekly ā ā level. I kept the set compact to avoid redundant features. ā ā ā ā Note: the LLM-suggested lags and window_features are hypotheses, not validated ā ā improvements. Confirm any expected accuracy gain before relying on them. ā ā ā ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⯠Predictions (36 rows) āāāāāāāāāāāāāāāāāāāāāāā³āāāāāāāāāāā³āāāāāāāāāāāāāā³āāāāāāāāāāāāāā ā Index ā pred ā lower_bound ā upper_bound ā ā”āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā© ā 2013-01-01 00:00:00 ā 21.1225 ā 13.8129 ā 33.1727 ā āāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2013-01-01 01:00:00 ā 12.3486 ā 3.7501 ā 26.1998 ā āāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2013-01-01 02:00:00 ā 9.2217 ā 3.8317 ā 19.0455 ā āāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2013-01-01 03:00:00 ā 5.1839 ā 0.9980 ā 12.5029 ā āāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2013-01-01 04:00:00 ā 5.3510 ā 1.0111 ā 11.1553 ā āāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā ... ā ... ā ... ā ... ā āāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2013-01-02 07:00:00 ā 113.3146 ā 79.5549 ā 171.9833 ā āāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2013-01-02 08:00:00 ā 276.7420 ā 162.0616 ā 368.8763 ā āāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2013-01-02 09:00:00 ā 242.5194 ā 192.8666 ā 284.7613 ā āāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2013-01-02 10:00:00 ā 154.3968 ā 122.7093 ā 208.1959 ā āāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2013-01-02 11:00:00 ā 170.9749 ā 133.4924 ā 223.2180 ā āāāāāāāāāāāāāāāāāāāāāāā“āāāāāāāāāāā“āāāāāāāāāāāāāā“āāāāāāāāāāāāāā
Code-only mode¶
Use forecast_code() when you want to preview or export the reproducible script without executing it. This is useful for code review, auditing the generated pipeline, or running the script in a separate environment.
# Generate the reproducible script without executing it
# ==============================================================================
code_result = assistant.forecast_code(
data = data,
steps = 36,
test_size = 36,
profile = profile,
plan = plan_refined
)
code_result.show_code()
The ForecastResult object¶
Both forecast() modes return a ForecastResult, a lightweight container that bundles everything the assistant used and produced.
| Attribute | Type | Description |
|---|---|---|
predictions |
DataFrame | Forecasted values. When intervals are requested, the bound columns are included alongside the point predictions. |
metrics |
DataFrame or None | Evaluation metrics, with the columns of a backtest: one per metric (mean_absolute_error, root_mean_squared_error, mean_absolute_scaled_error, mean_absolute_percentage_error) and, with several series, levels. None in prediction mode. |
code |
str | The exact standalone skforecast script that produced the forecast, ready to run on its own. |
profile |
ForecastingProfile |
The data profile behind the forecast. |
plan |
ForecastPlan |
The detailed configuration that was executed. |
Backtesting¶
The backtesting branch uses the same profile and plan as the forecast branch but evaluates the model's historical performance through time series cross-validation. The key decision is how to configure the TimeSeriesFold object, which controls exactly how the historical data is partitioned into successive training and test windows.
skforecast-ai provides three distinct ways to define this validation strategy:
Explicit instantiation (recommended): manually construct a
TimeSeriesFoldand pass it directly tobacktest(). Use this when you already know your exact operational constraints.Deterministic
create_cv(): allow the assistant to derive a sensibleTimeSeriesFoldfrom the profile and plan using rule-based defaults. You can override individual parameters explicitly.LLM
create_cv()(with a prompt): describe your deployment use case in natural language. The LLM translates your description into a fully-configuredTimeSeriesFold, accompanied by an explanation you can audit.
Define the backtesting strategy¶
Manual TimeSeriesFold¶
# Create your own TimeSeriesFold object
# ==============================================================================
end_train = '2012-08-31 23:59:00'
cv = TimeSeriesFold(
steps = 36,
initial_train_size = end_train,
refit = False,
verbose = False
)
cv
TimeSeriesFold
General Information
- Initial train size: 2012-08-31 23:59:00
- Initial train size as int: None
- Steps: 36
- Fold stride: 36
- Overlapping folds: False
- Window size: None
- Refit: False
- Fixed train size: True
- Gap: 0
- Skip folds: None
- Allow incomplete fold: True
- Return all indexes: False
Deterministic create_cv()¶
Only initial_train_size is passed here; the rest of the strategy comes from the defaults. The explanation says which values you chose and why each default has its value.
# Let the assistant derive a TimeSeriesFold with rule-based defaults
# ==============================================================================
cv_det = assistant.create_cv(
profile = profile,
plan = plan_refined,
initial_train_size = end_train,
)
cv_det
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Cross-Validation Explanation āāāāāāāāāāāāāāāāāāāāāāāāāāāāāā® ā ā ā Initial training up to 2012-08-31 23:59:00, trained once (no refit), 36-step ā ā horizon, 82 folds (the last one has only 12 steps). Trained once by default: ā ā refitting in every fold would multiply the training cost by the 82 folds. ā ā initial_train_size as requested. ā ā ā ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⯠Cross-Validation Configuration āāāāāāāāāāāāāāāāāāāāāāāāā³āāāāāāāāāāāāāāāāāāāāāā ā Parameter ā Value ā ā”āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā© ā steps ā 36 ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāā⤠ā initial_train_size ā 2012-08-31 23:59:00 ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāā⤠ā refit ā False ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāā⤠ā fixed_train_size ā False ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāā⤠ā gap ā 0 ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāā⤠ā fold_stride ā 36 ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāā⤠ā skip_folds ā None ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāā⤠ā allow_incomplete_fold ā True ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāā⤠ā n_folds ā 82 ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāā⤠ā n_fits ā 1 ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāā⤠ā last_fold_steps ā 12 ā āāāāāāāāāāāāāāāāāāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāā
LLM create_cv() with a natural-language prompt¶
Rather than manually configuring TimeSeriesFold parameters, you can describe your backtesting strategy in natural language and let the assistant translate it into a rigorous cross-validation schema. The Agentic forecasting guide shows this translation in an animation.
# Let the assistant create the TimeSeriesFold from a natural-language prompt
# ==============================================================================
prompt = (
"I forecast bike demand 36 hours ahead. "
"The model should be trained once on all data up to the end of August 2012, 23:59. "
"Do not refit the model as the window rolls forward."
)
cv_llm = assistant.create_cv(
profile = profile,
plan = plan_refined,
prompt = prompt
)
# Cross-validation strategy derived from the prompt
# ==============================================================================
cv_llm
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Cross-Validation Explanation āāāāāāāāāāāāāāāāāāāāāāāāāāāāāā® ā ā ā Data is hourly from 2011-01-01 00:00. 2011 has 8760 hours. Jan-Aug 2012 (leap year) ā ā has 244 days, or 5856 hours. Training through 2012-08-31 23:00 therefore gives 14616 ā ā observations, so initial_train_size=14616. This is far above the minimum viable size ā ā of 372 (max_lag 336). The remaining 2928 hours (Sep-Dec 2012) give about 81 folds of ā ā 36 steps, well over the 2-fold minimum. The user wants the model trained once with ā ā no refitting, so refit=False. fixed_train_size has no effect without refit, so it ā ā stays at its default. No deployment delay was mentioned, so gap=0. fold_stride stays ā ā at the default (equal to steps, 36), so test sets do not overlap. Using 83% of data ā ā (14616 observations) for initial training, trained once (no refit), 36-step horizon, ā ā 82 folds (the last one has only 12 steps). ā ā ā ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⯠Cross-Validation Configuration āāāāāāāāāāāāāāāāāāāāāāāāā³āāāāāāāā ā Parameter ā Value ā ā”āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā© ā steps ā 36 ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāā⤠ā initial_train_size ā 14616 ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāā⤠ā refit ā False ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāā⤠ā fixed_train_size ā False ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāā⤠ā gap ā 0 ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāā⤠ā fold_stride ā 36 ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāā⤠ā skip_folds ā None ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāā⤠ā allow_incomplete_fold ā True ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāā⤠ā n_folds ā 82 ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāā⤠ā n_fits ā 1 ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāā⤠ā last_fold_steps ā 12 ā āāāāāāāāāāāāāāāāāāāāāāāāā“āāāāāāāā
# LLM reasoning behind the TimeSeriesFold configuration
# ==============================================================================
print(textwrap.fill(cv_llm.explanation, width=88))
Data is hourly from 2011-01-01 00:00. 2011 has 8760 hours. Jan-Aug 2012 (leap year) has 244 days, or 5856 hours. Training through 2012-08-31 23:00 therefore gives 14616 observations, so initial_train_size=14616. This is far above the minimum viable size of 372 (max_lag 336). The remaining 2928 hours (Sep-Dec 2012) give about 81 folds of 36 steps, well over the 2-fold minimum. The user wants the model trained once with no refitting, so refit=False. fixed_train_size has no effect without refit, so it stays at its default. No deployment delay was mentioned, so gap=0. fold_stride stays at the default (equal to steps, 36), so test sets do not overlap. Using 83% of data (14616 observations) for initial training, trained once (no refit), 36-step horizon, 82 folds (the last one has only 12 steps).
Since the prompt correctly describes the intended use case, the cv_llm object returned by create_cv() is equivalent to the one we built manually (the same 82 folds; the timestamp is aligned to the hourly frequency). However, it was derived entirely from a natural-language description. The returned CVResult carries the splitter as cv_llm.cv and, as cv_llm.explanation, a description of the choices the assistant made, allowing you to verify that the resulting TimeSeriesFold matches your intended strategy before executing the backtest.
Run the backtest¶
# Run backtesting, reusing the pre-computed profile and plan
# ==============================================================================
results_backtest = assistant.backtest(
data = data,
cv = cv, # TimeSeriesFold, or a CVResult from create_cv()
interval = [0.1, 0.9], # 80% prediction interval
profile = profile, # Reuse the pre-computed profile
plan = plan_refined # Reuse the refined plan
)
results_backtest.show_explanation()
display(results_backtest.metrics)
display(results_backtest.predictions.head())
/var/folders/wt/8tvn563d5v55nspfbydgqb9r0000gp/T/ipykernel_87469/3887262773.py:3: IntervalCoverageWarning: The prediction interval [0.1, 0.9] has a nominal coverage of 80 %, but only 62.6 % of the 2928 actual values of the backtest fell inside it (more than 2 binomial standard errors for the number of predictions, and at least 5 percentage points, below 80 %). Do not present this interval as covering 80 %: report the coverage measured in the backtest (the `coverage` column of the metrics). results_backtest = assistant.backtest(
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Backtest Explanation āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā® ā ā ā Initial training up to 2012-08-31 23:59:00, trained once (no refit), 36-step ā ā horizon, 82 folds (the last one has only 12 steps). Results: mean_absolute_error: ā ā 48.1383, root_mean_squared_error: 79.2586, mean_absolute_scaled_error: 0.7571, ā ā mean_absolute_percentage_error: 0.5589. They are measured on 2928 predictions with ā ā an observed value (n_evaluated). Prediction interval [0.1, 0.9] (nominal coverage 80 ā ā %): 62.6 % of the 2928 actual values fell inside it (coverage: 0.6264), with a mean ā ā width of 83.5861 in the units of the target (interval_width). ā ā ā ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāÆ
| mean_absolute_error | root_mean_squared_error | mean_absolute_scaled_error | mean_absolute_percentage_error | coverage | interval_width | n_evaluated | |
|---|---|---|---|---|---|---|---|
| 0 | 48.138281 | 79.258594 | 0.757107 | 0.558892 | 0.626366 | 83.586126 | 2928 |
| fold | step | y_true | pred | lower_bound | upper_bound | |
|---|---|---|---|---|---|---|
| 2012-09-01 00:00:00 | 0 | 1 | 168.0 | 116.973395 | 90.516665 | 142.509589 |
| 2012-09-01 01:00:00 | 0 | 2 | 79.0 | 96.550804 | 62.958791 | 120.704363 |
| 2012-09-01 02:00:00 | 0 | 3 | 69.0 | 56.998001 | 35.026328 | 79.646127 |
| 2012-09-01 03:00:00 | 0 | 4 | 35.0 | 28.668120 | 8.758691 | 49.434241 |
| 2012-09-01 04:00:00 | 0 | 5 | 12.0 | 12.984980 | 5.246626 | 25.689067 |
The plot opens on ten days of October, where the predictions, the actual values and the interval can be told apart. Double-click on it to see the whole test period, from September to December 2012.
# Plot prediction intervals vs real value
# ==============================================================================
predictions = results_backtest.predictions
data_test = data.set_index("date_time").loc[predictions.index, :]
fig = go.Figure([
go.Scatter(name='Prediction', x=predictions.index, y=predictions['pred'], mode='lines'),
go.Scatter(
name='Real value', x=data_test.index, y=data_test['users'], mode='lines',
),
go.Scatter(
name='Upper Bound', x=predictions.index, y=predictions['upper_bound'], mode='lines',
marker=dict(color="#444"), line=dict(width=0), showlegend=False
),
go.Scatter(
name='Lower Bound', x=predictions.index, y=predictions['lower_bound'], marker=dict(color="#444"),
line=dict(width=0), mode='lines', fillcolor='rgba(68, 68, 68, 0.3)', fill='tonexty', showlegend=False
)
])
fig.update_layout(
title="Real value vs predicted in test data",
xaxis_title="Date time",
yaxis_title="users",
width=800,
height=400,
margin=dict(l=20, r=20, t=35, b=20),
hovermode="x",
legend=dict(orientation="h", yanchor="top", y=1.1, xanchor="left", x=0.001),
# Initial zoom on x axis betwee 1 oct to 10 oct
xaxis=dict(range=['2012-10-01', '2012-10-10'])
)
fig.show()
# Ask the assistant to interpret the backtesting results
# ==============================================================================
answer = assistant.ask(
prompt = (
"Explain the results of this backtesting, including the strategy, metrics, "
"and predictions. Is the model good enough to deploy?"
),
context = results_backtest
)
answer.show_explanation()
/var/folders/wt/8tvn563d5v55nspfbydgqb9r0000gp/T/ipykernel_87469/2899763076.py:3: DataSentToLLMWarning: `send_data_to_llm=False` does not apply to `context`: the predicted values it carries are sent to the LLM, because a question about a result cannot be answered from summary statistics alone. Your input data is not sent: the observed values that the predictions of a backtest carry (`y_true`) are left out, and a result holds no other value of the data it was fitted on. To keep predictions local, ask without `context`. answer = assistant.ask(
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Assistant Response āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā® ā ā ā The backtest shows a model that beats the one-step naive forecast on point accuracy ā ā (MASE 0.7571), but its 80% prediction intervals are too narrow (coverage 0.6264). ā ā Whether it is good enough to deploy depends on an error tolerance for your use case, ā ā which is not in the context, so I can't make that call. If you need reliable ā ā uncertainty ranges, the interval calibration is a concern. ā ā ā ā Strategy ā ā ā ā ⢠ForecasterRecursive with LGBMRegressor, forecasting 36 hours ahead. ā ā ⢠The model was trained once on data up to 2012-08-31 23:59:00 and never refit ā ā (refit False, 1 fit in total). The results therefore reflect a model deployed ā ā without retraining. ā ā ⢠The test span runs from 2012-09-01 to 2012-12-31 in 82 non-overlapping folds of ā ā 36 steps. The last fold has only 12 steps. ā ā ⢠The metrics are measured on 2928 predictions that have an observed value. ā ā ⢠The plan uses 20 lags, window features (means and standard deviations over 3 and ā ā 24 hours, plus a 168-hour mean), calendar features, and the exogenous variables ā ā holiday, weather and temp. ā ā ⢠The lag and window choices came from an LLM refinement step and are hypotheses, ā ā not validated improvements. This backtest measures this one configuration, so it ā ā cannot show whether that refinement helped. ā ā ā ā Point accuracy ā ā ā ā ⢠MAE is 48.1383 and RMSE is 79.2586, in the units of the target. For scale, the ā ā target has a mean of 187.8 and a standard deviation of 181.3. ā ā ⢠MASE is 0.7571. Below 1 means the model beats the one-step naive forecast (repeat ā ā the previous value). ā ā ⢠MAPE is 0.5589, quoted as a fraction. The target's minimum is 1, so near-zero ā ā values make MAPE hard to interpret. I would lean on MAE and MASE instead. ā ā ā ā Prediction intervals ā ā ā ā ⢠The interval is [0.1, 0.9], so nominal coverage is 80%. Observed coverage is ā ā 0.6264, meaning 62.6% of actual values fell inside it. ā ā ⢠That is below the nominal level, so the intervals appear too narrow and ā ā understate uncertainty. The mean width is 83.5861. ā ā ⢠Some lower bounds go negative (the minimum is -3.6258784440759078), although the ā ā target's minimum is 1. If you need non-negative ranges, those bounds would need ā ā handling downstream. ā ā ā ā Predictions ā ā ā ā Only 10 of the 2928 rows are shown, so I can't describe patterns across the horizon. ā ā Across all rows, predictions range from 0.5846345040897365 to 892.6309557332962, ā ā with a mean of 241.573051265072. ā ā ā ā Before deploying ā ā ā ā ⢠I can't tell how much accuracy varies from fold to fold, because per-fold results ā ā are not provided. The aggregate MAE therefore hides any weak stretches. ā ā ⢠With no refit, the model is never updated during the test span. A production ā ā setup that retrains regularly may behave differently, and assistant.backtest() ā ā can measure that with a different refit setting. ā ā ⢠To check whether this configuration is the best choice, assistant.compare() can ā ā rank it against the alternative forecasters or estimators from the profile. ā ā ⢠I can't validate whether the 48.1383 MAE is acceptable for your decisions. That ā ā is a business judgment. ā ā ā ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāÆ
Code-only mode¶
Use backtest_code() to generate the reproducible backtesting script without executing it.
# Generate the reproducible backtest script without executing it
# ==============================================================================
code_bt = assistant.backtest_code(
data = data,
cv = cv,
profile = profile,
plan = plan_refined
)
code_bt.show_code()
The BacktestResult object¶
The backtest() method returns a BacktestResult, a lightweight container that bundles all the backtesting artifacts.
| Attribute | Type | Description |
|---|---|---|
predictions |
DataFrame | Full out-of-sample backtest predictions across all folds. |
metrics |
DataFrame | Backtesting metrics (mean_absolute_error, root_mean_squared_error, mean_absolute_scaled_error, mean_absolute_percentage_error), one row per series, computed across all folds. |
cv_config |
dict | Resolved TimeSeriesFold parameters for full traceability of the validation strategy. |
code |
str | The exact standalone skforecast script that reproduces the backtesting workflow. |
explanation |
str | Human-readable summary of the backtesting configuration and results. |
profile |
ForecastingProfile |
The data profile behind the backtest. |
plan |
ForecastPlan |
The detailed configuration that was executed. |
# Full results object
# ==============================================================================
results_backtest
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Backtest Explanation āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā® ā ā ā Initial training up to 2012-08-31 23:59:00, trained once (no refit), 36-step ā ā horizon, 82 folds (the last one has only 12 steps). Results: mean_absolute_error: ā ā 48.1383, root_mean_squared_error: 79.2586, mean_absolute_scaled_error: 0.7571, ā ā mean_absolute_percentage_error: 0.5589. They are measured on 2928 predictions with ā ā an observed value (n_evaluated). Prediction interval [0.1, 0.9] (nominal coverage 80 ā ā %): 62.6 % of the 2928 actual values fell inside it (coverage: 0.6264), with a mean ā ā width of 83.5861 in the units of the target (interval_width). ā ā ā ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⯠Cross-Validation Configuration āāāāāāāāāāāāāāāāāāāāāāāāā³āāāāāāāāāāāāāāāāāāāāāā ā Parameter ā Value ā ā”āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā© ā steps ā 36 ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāā⤠ā initial_train_size ā 2012-08-31 23:59:00 ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāā⤠ā refit ā False ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāā⤠ā fixed_train_size ā True ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāā⤠ā gap ā 0 ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāā⤠ā fold_stride ā 36 ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāā⤠ā skip_folds ā None ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāā⤠ā allow_incomplete_fold ā True ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāā⤠ā n_folds ā 82 ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāā⤠ā n_fits ā 1 ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāā⤠ā last_fold_steps ā 12 ā āāāāāāāāāāāāāāāāāāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāā Backtest Metrics āāāāāāāāāāāāāā³āāāāāāāāāāāāā³āāāāāāāāāāāāā³āāāāāāāāāāāāā³āāāāāāāāāāā³āāāāāāāāāāāāā³āāāāāāāāāāāāā ā mean_abso⦠ā root_mean⦠ā mean_abso⦠ā mean_abso⦠ā coverage ā interval_⦠ā n_evaluat⦠ā ā”āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā© ā 48.1383 ā 79.2586 ā 0.7571 ā 0.5589 ā 0.6264 ā 83.5861 ā 2,928 ā āāāāāāāāāāāāāā“āāāāāāāāāāāāā“āāāāāāāāāāāāā“āāāāāāāāāāāāā“āāāāāāāāāāā“āāāāāāāāāāāāā“āāāāāāāāāāāāā Backtest Predictions (2928 rows) āāāāāāāāāāāāāāāāāāāā³āāāāāāāāāā³āāāāāāāāāā³āāāāāāāāāāā³āāāāāāāāāāā³āāāāāāāāāāāāāā³āāāāāāāāāāāāāā ā Index ā fold ā step ā y_true ā pred ā lower_bound ā upper_bound ā ā”āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā© ā 2012-09-01 ā 0.0000 ā 1.0000 ā 168.0000 ā 116.9734 ā 90.5167 ā 142.5096 ā ā 00:00:00 ā ā ā ā ā ā ā āāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2012-09-01 ā 0.0000 ā 2.0000 ā 79.0000 ā 96.5508 ā 62.9588 ā 120.7044 ā ā 01:00:00 ā ā ā ā ā ā ā āāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2012-09-01 ā 0.0000 ā 3.0000 ā 69.0000 ā 56.9980 ā 35.0263 ā 79.6461 ā ā 02:00:00 ā ā ā ā ā ā ā āāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2012-09-01 ā 0.0000 ā 4.0000 ā 35.0000 ā 28.6681 ā 8.7587 ā 49.4342 ā ā 03:00:00 ā ā ā ā ā ā ā āāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2012-09-01 ā 0.0000 ā 5.0000 ā 12.0000 ā 12.9850 ā 5.2466 ā 25.6891 ā ā 04:00:00 ā ā ā ā ā ā ā āāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā ... ā ... ā ... ā ... ā ... ā ... ā ... ā āāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2012-12-31 ā 81.0000 ā 8.0000 ā 119.0000 ā 180.1349 ā 131.5805 ā 269.2406 ā ā 19:00:00 ā ā ā ā ā ā ā āāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2012-12-31 ā 81.0000 ā 9.0000 ā 89.0000 ā 148.1796 ā 106.9945 ā 201.2459 ā ā 20:00:00 ā ā ā ā ā ā ā āāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2012-12-31 ā 81.0000 ā 10.0000 ā 90.0000 ā 106.8954 ā 69.4522 ā 140.9718 ā ā 21:00:00 ā ā ā ā ā ā ā āāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2012-12-31 ā 81.0000 ā 11.0000 ā 61.0000 ā 63.5536 ā 36.4563 ā 89.3625 ā ā 22:00:00 ā ā ā ā ā ā ā āāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2012-12-31 ā 81.0000 ā 12.0000 ā 49.0000 ā 36.3347 ā 18.3174 ā 54.1077 ā ā 23:00:00 ā ā ā ā ā ā ā āāāāāāāāāāāāāāāāāāāā“āāāāāāāāāā“āāāāāāāāāā“āāāāāāāāāāā“āāāāāāāāāāā“āāāāāāāāāāāāāā“āāāāāāāāāāāāāā Dataset Profile āāāāāāāāāāāāāāāāāā³āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā Property ā Value ā ā”āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā© ā Format ā single ā āāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Series ā 1 ā āāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Observations ā 17544 ā āāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Frequency ā h ā āāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Target ā users ā āāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Exog columns ā holiday, weather, temp (categorical: weather) ā āāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Missing values ā None ā āāāāāāāāāāāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Recommendation āāāāāāāāāāāāāāāāāāāāāāāāā³āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā Property ā Value ā ā”āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā© ā Task type ā single_series ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Forecaster ā ForecasterRecursive ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Forecaster candidates ā ForecasterRecursive, ForecasterDirect, ForecasterFoundation ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Estimator ā LGBMRegressor ā āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Estimator candidates ā LGBMRegressor, XGBRegressor, Ridge ā āāāāāāāāāāāāāāāāāāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Profile Explanation āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā® ā ā ā A single-series ML forecaster (ForecasterRecursive) is recommended. Data: 17544 ā ā observations, 'h' frequency. Alternative forecasters: ['ForecasterDirect', ā ā 'ForecasterFoundation']. Estimator: LGBMRegressor. A gradient boosting model is ā ā preferred for a dataset of this size (17544 observations). Alternative estimators: ā ā ['XGBRegressor', 'Ridge']. 3 exogenous variables (1 categorical) available as ā ā predictors. ā ā ā ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⯠Forecast Plan āāāāāāāāāāāāāāāāāāāāā³āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā Property ā Value ā ā”āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā© ā Task type ā single_series ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Forecaster ā ForecasterRecursive ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Estimator ā LGBMRegressor ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Steps ā 36 ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Frequency ā h ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Lags ā [1, 2, 3, 4, 5, 6, 12, 23, 24, 25, 47, 48, 72, 96, 120, 144, 167, ā ā ā 168, 169, 336] (LLM-suggested) ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Window features ā [{'stats': ['mean', 'std'], 'window_size': 3}, {'stats': ['mean', ā ā ā 'std'], 'window_size': 24}, {'stats': ['mean'], 'window_size': ā ā ā 168}] (LLM-suggested) ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Calendar features ā ['hour', 'day_of_week', 'weekend', 'month'] (raw ordinal encoding) ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Use exog ā True ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Interval ā [0.1, 0.9] ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Interval method ā bootstrapping ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Primary metric ā mean_absolute_error ā āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Preprocessing ā 1 step ā āāāāāāāāāāāāāāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Preprocessing Steps āāāāāāāāāāāāāāāāāāāāāāāāāāā³āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā Step ā Reason ā ā”āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā© ā handle_categorical_exog ā Categorical exogenous variables detected: ['weather']. These ā ā ā are handled automatically by skforecast ā ā ā (categorical_features='auto'). ā āāāāāāāāāāāāāāāāāāāāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Plan Explanation āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā® ā ā ā Plan: ForecasterRecursive + LGBMRegressor. Lags: [1, 2, 3, 4, 5, 6, 12, 23, 24, 25, ā ā 47, 48, 72, 96, 120, 144, 167, 168, 169, 336]. Window features: ['mean(window=3)', ā ā 'std(window=3)', 'mean(window=24)', 'std(window=24)', 'mean(window=168)']. Calendar ā ā features: ['hour', 'day_of_week', 'weekend', 'month'] (raw ordinal encoding). ā ā Prediction intervals via bootstrapping. Exogenous variables included. MAE is ā ā interpretable, robust to outliers, and works at any scale. ā ā ā ā LLM Refinement Reasoning: Short lags 1-6 capture the current trend over the last few ā ā hours. Lags 12, 23, 24 and 25 capture the daily rhythm, so the same hour yesterday ā ā and its neighbours help with the rush-hour peaks. Lags 47, 48, 72, 96, 120 and 144 ā ā give the same hour on earlier days. Lags 167, 168 and 169 capture same hour last ā ā week, which separates weekday from weekend behaviour. Lag 336 adds the same hour two ā ā weeks ago for a more robust weekly reference. This replaces the sparse, irregular ā ā set of lags with a structured one tied to the daily and weekly cycles. Window ā ā features add a short 3-hour mean and std for recent level and volatility, a 24-hour ā ā mean and std for the daily level and variability, and a 168-hour mean for the weekly ā ā level. I kept the set compact to avoid redundant features. ā ā ā ā Note: the LLM-suggested lags and window_features are hypotheses, not validated ā ā improvements. Confirm any expected accuracy gain before relying on them. ā ā ā ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāÆ
Comparing forecaster configurations¶
Choosing a forecasting model should not rely on intuition alone. Two configurations that look equally reasonable can perform very differently once evaluated on real temporal data. The most reliable approach is to test every candidate under identical conditions and compare their metrics.
The compare() method does exactly that. It receives a list of candidate configurations, backtests each one using the same TimeSeriesFold strategy, and returns a leaderboard ranked by the selected metric.
In the step-by-step path, the key argument is profile. Passing the profile computed at the beginning of this tutorial skips profiling entirely and guarantees that every candidate is evaluated against the same data profile. Note that compare() does not accept a plan: each candidate derives its own plan from the shared profile, which is precisely what makes the candidates differ.
Candidates can be provided in two ways:
Automatic candidates (
candidates=None): the assistant builds the comparison set from theprofile.forecaster_candidatesthat belong to the same family as the recommended forecaster, so every row is scored on the same thing. For multi-series data, a multi-series forecaster is never ranked against a multivariate one:ForecasterRecursiveMultiSeriesis compared withForecasterFoundation. This is useful when exploring a new dataset without a predefined shortlist. Whencvis theCVResultofcreate_cv()for a plan that is none of those candidates (a plan refined with another estimator or other lags, for example), that plan runs too, as the row'Strategy plan', and the summary names it.Explicit candidates (recommended): pass a list of
(name, config)tuples, wherenamelabels the row in the leaderboard andconfigholds the same override keys understood byplan():'forecaster','estimator','estimator_kwargs','lags','window_features','use_exog','differentiation','calendar_features','target_transformer'and'dropna_from_series'. This provides full control and makes the resulting table easier to interpret.
For a single series, compare() also adds a seasonal naive baseline (ForecasterEquivalentDate, which repeats the value of one seasonal period earlier, or the last value when the frequency has none) as one more row, ranked like the others, so the leaderboard shows whether a model beats the simplest reasonable forecast. Pass baseline=False to leave it out.
A failed candidate does not stop the comparison. Instead, a CandidateFailedWarning is issued, the row records the error and is placed last.
The Agentic forecasting guide shows a comparison in an animation: the candidates run through the same folds, and the leaderboard is a plain sort of the metric.
š” Tip
All candidates use the same cross-validation strategy, ensuring a fair comparison. However, the results are only meaningful if the cv setup reflects the real use case where the model will be deployed. For example, if the production system retrains weekly, the backtest should also refit weekly. If the model is expected to forecast 24 hours ahead, the backtest should use a 24-hour horizon.
The evaluation window must also be representative. A period that is too short or dominated by unusual events (holidays, outages, or exceptional peaks) may favor a candidate that performs poorly over time. Define the validation setup carefully before comparing models so the final ranking is reliable.
Automatic candidates¶
# Compare the forecaster candidates suggested by the profile
# ==============================================================================
results_compare = assistant.compare(
data = data,
cv = cv, # Same TimeSeriesFold used in the backtest above
candidates = None, # Candidates suggested by the assistant
profile = profile # Reuse the pre-computed profile
)
# Ranked leaderboard
# ==============================================================================
results_compare.results
| rank | name | forecaster | estimator | mean_absolute_error | root_mean_squared_error | mean_absolute_scaled_error | mean_absolute_percentage_error | n_evaluated | |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | ForecasterFoundation | ForecasterFoundation | autogluon/chronos-2-small | 38.436159 | 65.048643 | 0.605517 | 0.611349 | 2928 |
| 1 | 2 | ForecasterRecursive | ForecasterRecursive | LGBMRegressor | 46.312218 | 74.134214 | 0.729017 | 0.472735 | 2928 |
| 2 | 3 | ForecasterDirect | ForecasterDirect | LGBMRegressor | 49.298312 | 77.049481 | 0.776211 | 0.499413 | 2928 |
| 3 | 4 | Baseline (seasonal naive) | ForecasterEquivalentDate | None | 91.668716 | 150.507112 | 1.445666 | 0.912133 | 2928 |
# Deterministic summary of the comparison
# ==============================================================================
results_compare.show_explanation()
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Comparison Explanation āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā® ā ā ā Compared 4 configurations, ranked ascending by mean_absolute_error. Shared ā ā cross-validation strategy: Initial training up to 2012-08-31 23:59:00, trained once ā ā (no refit), 36-step horizon, 82 folds (the last one has only 12 steps). ā ā ForecasterFoundation is not trained: the window and refit settings do not apply to ā ā it, each fold forecasts from the observations before it. Each configuration is ā ā measured on 2928 predictions with an observed value (n_evaluated in the table: a ā ā count, not a metric, and it does not change the ranking). Best: ā ā 'ForecasterFoundation' (ForecasterFoundation / autogluon/chronos-2-small) = 38.4362, ā ā 17.0% ahead of 'ForecasterRecursive' (46.3122). All 3 configurations beat the ā ā baseline 'Baseline (seasonal naive)' (91.6687). The best, 'ForecasterFoundation', ā ā beats it by 58.1%. ā ā ā ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāÆ
Explicit candidates¶
In practice, you will often already have a shortlist in mind: a fast baseline, a gradient boosting model, or a variant with a richer feature set. Passing explicit (name, config) tuples keeps the comparison focused and makes the resulting leaderboard easy to understand at a glance.
The config dictionary accepts the same overrides as plan(). Any omitted option falls back to the deterministic recommendation derived from the shared profile, so candidates can remain concise. For example, {'forecaster': 'ForecasterDirect'} changes only the forecaster while keeping the recommended estimator, lags, and features.
ā ļø Computational cost
Each candidate is backtested independently across all folds, so runtime increases with both the number and complexity of the configurations. Comparing four candidates will take roughly four times as long as running one backtest.
Start with a small set of clearly different options, review the results, and refine from there. Testing many near-identical variants is costly and rarely useful.
# Compare an explicit shortlist of configurations
# ==============================================================================
candidates = [
(
"ridge_baseline",
{
"forecaster": "ForecasterRecursive",
"estimator" : "Ridge",
"lags" : 24,
}
),
(
"lgbm_daily_lags",
{
"forecaster": "ForecasterRecursive",
"estimator" : "LGBMRegressor",
"lags" : 24,
}
),
(
"refined_plan",
{
"forecaster" : plan_refined.forecaster,
"estimator" : plan_refined.estimator,
"lags" : plan_refined.forecaster_kwargs.get("lags"),
"window_features" : plan_refined.forecaster_kwargs.get("window_features"),
}
),
(
"lgbm_direct",
{
"forecaster": "ForecasterDirect",
"estimator" : "LGBMRegressor",
"lags" : 24,
}
),
(
"foundation_model",
{
"forecaster": "ForecasterFoundation"
}
),
]
results_compare = assistant.compare(
data = data,
cv = cv,
candidates = candidates, # Specific candidates to compare
metric = ['mean_absolute_error', 'mean_absolute_scaled_error'],
profile = profile
)
The refined_plan candidate reuses the forecaster, estimator, lags and window features of the plan produced by refine_plan(). This is the recommended way to validate a refined plan: the leaderboard shows whether the extra domain knowledge actually improves the metrics compared to the deterministic baselines. Passing create_cv(profile=profile, plan=plan_refined) as cv with candidates=None does the same with the candidates of the profile: the refined plan is the row 'Strategy plan'.
When several metrics are requested, all of them are shown as columns but only the first one drives the ranking.
# Ranked leaderboard, sorted by the first metric requested
# ==============================================================================
results_compare.results
| rank | name | forecaster | estimator | mean_absolute_error | mean_absolute_scaled_error | n_evaluated | |
|---|---|---|---|---|---|---|---|
| 0 | 1 | foundation_model | ForecasterFoundation | autogluon/chronos-2-small | 38.436159 | 0.605517 | 2928 |
| 1 | 2 | refined_plan | ForecasterRecursive | LGBMRegressor | 48.138281 | 0.757107 | 2928 |
| 2 | 3 | lgbm_direct | ForecasterDirect | LGBMRegressor | 50.224908 | 0.790885 | 2928 |
| 3 | 4 | lgbm_daily_lags | ForecasterRecursive | LGBMRegressor | 55.517689 | 0.874763 | 2928 |
| 4 | 5 | Baseline (seasonal naive) | ForecasterEquivalentDate | None | 91.668716 | 1.445666 | 2928 |
| 5 | 6 | ridge_baseline | ForecasterRecursive | Ridge | 93.145620 | 1.468844 | 2928 |
Inspect individual candidates¶
Because every candidate is a full BacktestResult, the details of any individual configuration remain available, including its metrics, its predictions and the standalone script that generated them.
# Inspect a specific candidate
# ==============================================================================
candidate = results_compare.candidates['foundation_model']
display(candidate.metrics)
display(candidate.predictions.head())
candidate.show_code()
| mean_absolute_error | mean_absolute_scaled_error | n_evaluated | |
|---|---|---|---|
| 0 | 38.436159 | 0.605517 | 2928 |
| level | fold | step | y_true | pred | |
|---|---|---|---|---|---|
| 2012-09-01 00:00:00 | users | 0 | 1 | 168.0 | 148.059464 |
| 2012-09-01 01:00:00 | users | 0 | 2 | 79.0 | 102.715004 |
| 2012-09-01 02:00:00 | users | 0 | 3 | 69.0 | 66.084412 |
| 2012-09-01 03:00:00 | users | 0 | 4 | 35.0 | 40.878693 |
| 2012-09-01 04:00:00 | users | 0 | 5 | 12.0 | 29.577866 |
Reuse the winning configuration¶
The most useful result of a comparison is often not the leaderboard, but best_candidate. It is a complete BacktestResult carrying both the winning profile and plan, so it can be fed back into the step-by-step workflow without manually rebuilding the configuration.
# Winning configuration
# ==============================================================================
print(f"Best candidate: {results_compare.best_name}")
results_compare.best_candidate.plan
Best candidate: foundation_model
Forecast Plan āāāāāāāāāāāāāāāāāā³āāāāāāāāāāāāāāāāāāāāāāāāāāāā ā Property ā Value ā ā”āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā© ā Task type ā foundation ā āāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Forecaster ā ForecasterFoundation ā āāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Estimator ā autogluon/chronos-2-small ā āāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Steps ā 36 ā āāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Frequency ā h ā āāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Use exog ā True ā āāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Interval ā None ā āāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Primary metric ā mean_absolute_error ā āāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāā⤠ā Preprocessing ā 1 step ā āāāāāāāāāāāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāāāāāāāā Preprocessing Steps āāāāāāāāāāāāāāāāāāāāāāāāāāā³āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā Step ā Reason ā ā”āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā© ā handle_categorical_exog ā Categorical exogenous variables detected: ['weather']. ā ā ā 'autogluon/chronos-2-small' consumes categorical covariates ā ā ā natively, so no encoding is needed. ā āāāāāāāāāāāāāāāāāāāāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Plan Explanation āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā® ā ā ā Plan: ForecasterFoundation + autogluon/chronos-2-small. No lag or window features: ā ā the foundation model forecasts directly from the raw context window. Exogenous ā ā variables included. Primary metric: mean_absolute_error, as requested; also ā ā computed: mean_absolute_scaled_error. The model reads the last 8192 observations of ā ā the series as context; the series has 17544, so older observations are not used. ā ā ā ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāÆ
# Produce the final forecast with the winning configuration
# ==============================================================================
results_pred_best = assistant.forecast(
data = data,
steps = 36,
interval = [0.1, 0.9],
test_size = None, # Prediction mode
exog = exog, # Future values of exogenous variables
profile = results_compare.profile, # Shared profile
plan = results_compare.best_candidate.plan # Winning plan
)
results_pred_best.show_code()
Explain mode (comparison)¶
Like any other result, a ComparisonResult can be passed to ask() as context to have the ranking explained. The LLM restates what the leaderboard measured, not why one candidate beat another, and it cannot change the outcome: all metrics and rankings are computed deterministically before it sees the result.
# Ask the assistant to interpret the comparison
# ==============================================================================
answer = assistant.ask(
prompt = (
"Explain the comparison results. Is the margin between the top candidates "
"meaningful, or are they practically equivalent?"
),
context = results_compare
)
answer.show_explanation()
/var/folders/wt/8tvn563d5v55nspfbydgqb9r0000gp/T/ipykernel_87469/2209842622.py:3: DataSentToLLMWarning: `send_data_to_llm=False` does not apply to `context`: the predicted values it carries are sent to the LLM, because a question about a result cannot be answered from summary statistics alone. Your input data is not sent: the observed values that the predictions of a backtest carry (`y_true`) are left out, and a result holds no other value of the data it was fitted on. To keep predictions local, ask without `context`. answer = assistant.ask(
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Assistant Response āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā® ā ā ā The ranking is clear on the supplied numbers, but I can't say whether the margin ā ā between the top candidates is statistically meaningful. Per-fold errors and their ā ā spread are not in the context, so I can't judge whether the gaps are larger than ā ā fold-to-fold variation. I also won't call any pair "practically equivalent", because ā ā that would need information I don't have. ā ā ā ā What the leaderboard shows ā ā ā ā All six candidates were scored on the same 2928 predictions with an observed value, ā ā and the ranking is ascending mean_absolute_error: ā ā ā ā ⢠Rank 1, foundation_model (ForecasterFoundation, autogluon/chronos-2-small): MAE ā ā 38.436159, MASE 0.605517. ā ā ⢠Rank 2, refined_plan (ForecasterRecursive, LGBMRegressor): MAE 48.138281, MASE ā ā 0.757107. ā ā ⢠Rank 3, lgbm_direct (ForecasterDirect, LGBMRegressor): MAE 50.224908, MASE ā ā 0.790885. ā ā ⢠Rank 4, lgbm_daily_lags (ForecasterRecursive, LGBMRegressor): MAE 55.517689, MASE ā ā 0.874763. ā ā ⢠Rank 5, Baseline (seasonal naive) (ForecasterEquivalentDate): MAE 91.668716, MASE ā ā 1.445666. ā ā ⢠Rank 6, ridge_baseline (ForecasterRecursive, Ridge): MAE 93.145620, MASE ā ā 1.468844. ā ā ā ā The MASE column orders the candidates the same way as the MAE column. The target's ā ā mean is 187.8 and its standard deviation is 181.3, which gives the MAE values a ā ā scale. ā ā ā ā Reading the margins ā ā ā ā ⢠The top four candidates have MASE below 1, so they beat the one-step naive ā ā forecast (repeat the previous value). The seasonal naive row and ridge_baseline ā ā have MASE above 1, so they do not. ā ā ⢠The four leading candidates all beat the Baseline (seasonal naive) row on ā ā mean_absolute_error. Ridge does not. ā ā ⢠Between the top candidates, the ranking tells you who scored lower, not whether ā ā the difference would hold on new data. This applies to the first-versus-second ā ā gap and to the narrower second-versus-third gap alike. ā ā ⢠The leaderboard reports what happened, not why, so I can't attribute the ordering ā ā to any model characteristic. ā ā ā ā A caveat on the comparison ā ā ā ā The backtesting strategy applies differently to the foundation model. It is not ā ā trained, so only the folds apply to it. The other candidates are trained once on ā ā data up to 2012-08-31 23:59:00 without refit. Both setups use 36-step horizons over ā ā 82 folds, with the last fold covering 12 steps. I can't validate how this difference ā ā affects the comparison, so keep it in mind when reading the first-place result. ā ā ā ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāÆ
The ComparisonResult object¶
The compare() method returns a ComparisonResult, which groups the shared setup, the ranked leaderboard, and the individual backtests in a single object.
| Attribute | Type | Description |
|---|---|---|
results |
DataFrame | Ranked leaderboard, one row per candidate, sorted best to worst. Columns: rank, name, forecaster, estimator, the metric columns, and error when at least one candidate failed. |
candidates |
dict | Mapping of candidate name to the full BacktestResult object. |
failures |
dict | Mapping of candidate name to a CandidateFailure describing why it failed. Empty when every candidate succeeds. |
ranking_metric |
str | Name of the metric used to sort results. |
cv_config |
dict | Resolved TimeSeriesFold parameters plus the resulting n_folds, applied identically to every candidate. |
profile |
ForecastingProfile |
The shared data profile behind every candidate. |
explanation |
str | Deterministic, human-readable summary of the comparison. |
best_name |
str | Name of the top-ranked candidate. |
best_candidate |
BacktestResult |
Top-ranked candidate as a complete BacktestResult. |
baseline_name |
str, None | Name of the seasonal naive baseline row, or None when no baseline was added (multi-series data, baseline=False, or a target with missing values or missing timestamps). |
# Full results object
# ==============================================================================
results_compare
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Comparison Explanation āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā® ā ā ā Compared 6 configurations, ranked ascending by mean_absolute_error. Shared ā ā cross-validation strategy: Initial training up to 2012-08-31 23:59:00, trained once ā ā (no refit), 36-step horizon, 82 folds (the last one has only 12 steps). ā ā ForecasterFoundation is not trained: the window and refit settings do not apply to ā ā it, each fold forecasts from the observations before it. Each configuration is ā ā measured on 2928 predictions with an observed value (n_evaluated in the table: a ā ā count, not a metric, and it does not change the ranking). Best: 'foundation_model' ā ā (ForecasterFoundation / autogluon/chronos-2-small) = 38.4362, 20.2% ahead of ā ā 'refined_plan' (48.1383). 4 of 5 configurations beat the baseline 'Baseline ā ā (seasonal naive)' (91.6687); 'ridge_baseline' does not. The best, ā ā 'foundation_model', beats it by 58.1%. ā ā ā ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⯠Comparison Results āāāāāāāāā³āāāāāāā³āāāāāāāāāāāā³āāāāāāāāāāāā³āāāāāāāāāāāā³āāāāāāāāāāāāā³āāāāāāāāāāāā³āāāāāāāāāāāāā ā Index ā rank ā name ā forecast⦠ā estimator ā mean_abso⦠ā mean_abs⦠ā n_evaluat⦠ā ā”āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā© ā 0 ā 1 ā foundati⦠ā Forecast⦠ā autogluo⦠ā 38.4362 ā 0.6055 ā 2928 ā āāāāāāāāā¼āāāāāāā¼āāāāāāāāāāāā¼āāāāāāāāāāāā¼āāāāāāāāāāāā¼āāāāāāāāāāāāā¼āāāāāāāāāāāā¼āāāāāāāāāāāā⤠ā 1 ā 2 ā refined_⦠ā Forecast⦠ā LGBMRegr⦠ā 48.1383 ā 0.7571 ā 2928 ā āāāāāāāāā¼āāāāāāā¼āāāāāāāāāāāā¼āāāāāāāāāāāā¼āāāāāāāāāāāā¼āāāāāāāāāāāāā¼āāāāāāāāāāāā¼āāāāāāāāāāāā⤠ā 2 ā 3 ā lgbm_dir⦠ā Forecast⦠ā LGBMRegr⦠ā 50.2249 ā 0.7909 ā 2928 ā āāāāāāāāā¼āāāāāāā¼āāāāāāāāāāāā¼āāāāāāāāāāāā¼āāāāāāāāāāāā¼āāāāāāāāāāāāā¼āāāāāāāāāāāā¼āāāāāāāāāāāā⤠ā 3 ā 4 ā lgbm_dai⦠ā Forecast⦠ā LGBMRegr⦠ā 55.5177 ā 0.8748 ā 2928 ā āāāāāāāāā¼āāāāāāā¼āāāāāāāāāāāā¼āāāāāāāāāāāā¼āāāāāāāāāāāā¼āāāāāāāāāāāāā¼āāāāāāāāāāāā¼āāāāāāāāāāāā⤠ā 4 ā 5 ā Baseline ā Forecast⦠ā N/A ā 91.6687 ā 1.4457 ā 2928 ā ā ā ā (seasonal ā ā ā ā ā ā ā ā ā naive) ā ā ā ā ā ā āāāāāāāāā¼āāāāāāā¼āāāāāāāāāāāā¼āāāāāāāāāāāā¼āāāāāāāāāāāā¼āāāāāāāāāāāāā¼āāāāāāāāāāāā¼āāāāāāāāāāāā⤠ā 5 ā 6 ā ridge_ba⦠ā Forecast⦠ā Ridge ā 93.1456 ā 1.4688 ā 2928 ā āāāāāāāāā“āāāāāāā“āāāāāāāāāāāā“āāāāāāāāāāāā“āāāāāāāāāāāā“āāāāāāāāāāāāā“āāāāāāāāāāāā“āāāāāāāāāāāāā
Reproducible code¶
Every forecast or backtest workflow exposes the standalone skforecast script used to produce its results. This script is strictly deterministic, ensuring identical outputs for a given set of inputs and configurations. You can access the code at any time via the show_code() method.
Free-form Q&A¶
The ask() method is not limited to interpreting workflow objects. Without any context attached, it works as a general forecasting knowledge assistant, useful for clarifying methodology, choosing between approaches, or understanding metric trade-offs.
Without a context there is no task type to route on, so only the general choosing-a-forecaster skill is sent unless the question mentions a topic (intervals, backtesting, metrics, ...) that pulls in a specific one. Pass skills= to pick them yourself; the names sent are recorded in answer.skills. See Skills for the LLM.
# Ask a general forecasting question (no data or result required)
# ==============================================================================
answer = assistant.ask(
prompt = (
"For hourly demand with strong daily and weekly seasonality, when should "
"I prefer a direct forecasting strategy over a recursive one?"
)
)
answer.show_explanation()
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Assistant Response āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā® ā ā ā Start with a recursive forecaster (ForecasterRecursive) and prefer a direct one ā ā (ForecasterDirect) when the relationship between predictors and target changes ā ā significantly across the forecast horizon. Strong daily and weekly seasonality alone ā ā is not a reason to switch, since a recursive model can use seasonal lags, window ā ā features, and calendar exogenous variables. ā ā ā ā When direct is a good fit ā ā ā ā ⢠Horizon-dependent patterns: if the short-horizon and long-horizon relationships ā ā differ, one model reused recursively may fit them poorly. Direct trains one ā ā independent model per step, so each step can learn its own relationship. ā ā ⢠Error propagation is a concern: recursive predictions feed into later steps, so ā ā errors can accumulate. Direct models use only observed data at every step. ā ā ⢠Long horizons: the documentation lists long horizons where patterns change per ā ā step as the best case for direct. ā ā ā ā When recursive is usually preferable ā ā ā ā ⢠General purpose: it is the documented default and starting point. It trains a ā ā single model. ā ā ⢠Flexible horizon: steps can be chosen at predict time. Direct requires steps at ā ā initialization. ā ā ⢠Lower cost: direct stores one estimator per step, so it uses more memory and ā ā trains more slowly. Training can be parallelized with n_jobs. ā ā ⢠Short-to-medium horizons: these are the cases where recursive is documented as ā ā the best fit. ā ā ā ā Both strategies support ā ā ā ā ⢠Lags, window features (RollingFeatures), and exogenous variables, so weekly and ā ā daily structure can be encoded either way. ā ā ⢠Bootstrapping and conformal prediction intervals. ā ā ā ā How to decide for your data ā ā ā ā I can't tell from the question alone whether your demand relationship changes across ā ā the horizon, and I can't validate that without results. The reliable way to decide ā ā is empirical: ā ā ā ā ⢠Use assistant.compare() to choose between a recursive and a direct candidate on ā ā your data. ā ā ⢠Use assistant.backtest() to measure the accuracy of whichever you pick. ā ā ā ā Interpret the results against the one-step naive forecast (repeat the previous ā ā value) when using MASE or RMSSE. Per-fold spread may be needed to judge whether a ā ā small difference between the two strategies is meaningful. ā ā ā ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāÆ
Summary¶
This tutorial covered the step-by-step path of skforecast-ai. Here is a recap of what each stage does and when to use it:
| Step | Method | When to use |
|---|---|---|
| 1. Profile | profile() |
Always: produces the ForecastingProfile required by all downstream methods. |
| 2. Plan | plan() |
Always: converts the profile into an executable configuration. |
| 3. Refine plan | refine_plan() |
Optional: use when you want to override specific decisions (deterministic) or inject domain knowledge (LLM). Always evaluate the result. |
| 4a. Forecast | forecast() |
When you want future predictions or a held-out evaluation in a single execution. |
| 4a. Code only | forecast_code() |
When you want to preview or export the script without running it. |
| 4b. CV strategy | create_cv() |
When you want the assistant to derive or translate a TimeSeriesFold for you. |
| 4b. Backtest | backtest() |
When you want to evaluate the model over multiple historical folds. |
| 4b. Code only | backtest_code() |
When you want to preview or export the backtesting script without running it. |
| 4c. Compare | compare() |
When you want to rank several configurations under an identical cross-validation strategy and reuse the winner. |
| Any time | ask() |
When you want an LLM explanation of any intermediate object or result, or a general forecasting Q&A. |
The key advantage of this path is that the profile and plan are built once and reused across both the forecast and backtest branches. This avoids redundant profiling and ensures that both branches use the same modeling configuration. The same profile can also be handed to compare(), so every candidate is ranked against the very same data profile.
For a faster alternative that runs the entire pipeline in a single call, see the fast-path tutorial. For a comprehensive overview of backtesting mechanics, see the skforecast backtesting user guide.