Agentic forecasting with skforecast-ai¶
What is skforecast-ai?¶
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.
It is organized around a single core object, the ForecastingAssistant, which consists of two complementary components:
Deterministic Engine (Rule-based and Reproducible): Profiles the data, selects a forecaster and estimator, derives lags and preprocessing steps, runs backtesting, and produces the final forecast. Crucially, it outputs the exact standalone
skforecastscript that generated the results. Given the same inputs and configuration, this workflow is guaranteed to be reproducible.Reasoning Layer (LLM-powered): Accessed primarily via the
ask()method, this layer interprets and explains the objects and results you pass to it: data profiles, modeling plans, validation choices, backtesting outputs, and forecasts. The LLM acts strictly as an interpreter; it does not rerun the workflow or silently change modeling recommendations behind the scenes. Agentic features, such as the LLM-guidedrefine_plan()orcreate_cv(), are separate, explicit steps where the LLM suggests adjustments that are then implemented transparently in deterministic code.
The animation below follows one series through the assistant: what stays on your machine, what the LLM sees, and how its suggestions are validated before they reach the plan.
Two ways to use skforecast-ai¶
skforecast-ai supports two distinct workflows using the same underlying forecasting engine:
The Fast Path: Use this when you want a forecast or backtest result in a single call. The assistant profiles the data, builds the modeling plan, executes the workflow, and returns the results alongside the reproducible
skforecastcode.The Step-by-Step Path: Use this when you want granular control to inspect or adjust intermediate decisions. You can manually create a profile, build a plan, optionally refine it with the LLM, define a validation strategy, evaluate the model, and then generate the forecast.
A useful mental model is that forecasting and validation are separate branches. Once you have a profile and a plan, you can use forecast() to produce future predictions directly, or backtest() to evaluate the model's performance on historical data. You can also use compare() to evaluate several candidate configurations under the same cross-validation strategy and obtain a ranked leaderboard, so the best configuration is chosen from measured performance rather than intuition.
The ask() method is available in both workflows. It can explain a profile, a plan, a generated script, a validation setup, or a forecast, backtest or comparison result, or answer general forecasting questions. It never executes the workflow or modifies your parameters.
The following example walks through the fast path: the quickest way to go from raw data to a validated forecast with minimal setup. It is ideal when you want rapid results and trust the assistant to make sensible, baseline modeling decisions on your behalf. If you prefer to understand and control what happens under the hood step by step, visit the step-by-step path tutorial for a more detailed walkthrough.
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
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 assistant, 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 (for example, refine_plan() with explicit overrides and prompt=None) 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 reasoning layer
# ==============================================================================
# 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 in this document 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.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='Train')
)
fig.update_layout(
title = 'Number of users',
xaxis_title="Time",
yaxis_title="Users",
legend_title="Partition:",
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.
Forecasting with the assistant¶
The forecast() method is the fastest way to generate predictions. In a single call, it executes the full pipeline (profile ā plan ā execute) and returns a ForecastResult holding the predictions, the evaluation metrics (when available), and the exact standalone skforecast script that produced them.
The behavior is controlled by a single switch, test_size, which selects one of two modes:
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 to compare against, no metrics are returned. If the historical data contains exogenous variables, their future values must be explicitly supplied via theexogargument.Evaluation mode (
test_sizeis set). The dataset is split into train and test sets, the model is trained on the training portion, and predictions for the test window are compared against the held-out actuals to compute metrics. In this mode, the test-set exogenous values are taken from the split, soexogmust not be passed.
The main arguments are:
| Argument | Type | Description |
|---|---|---|
data |
Series, DataFrame, str, Path | Input dataset or path to a CSV file. When a Series is passed, the target is taken from its name. |
steps |
int | Forecast horizon (number of steps ahead to predict). |
target |
str, list of str | Column to forecast. Optional when data is a Series. Pass a list of column names for wide-format multi-series. |
date_column |
str | Column holding the timestamps. When None, the index of data must already be a DatetimeIndex. |
exog |
DataFrame, Series, str, Path | Future exogenous values covering the horizon (at least steps rows), or the path of a CSV file with them, read as the data are read and loaded by the script from that same path. Used only in prediction mode, and required there when the plan uses the exogenous variables of the data (a plan with use_exog=False, such as the seasonal naive baseline, rejects it). |
interval |
list of float | Prediction interval as [lower, upper] quantiles (e.g. [0.1, 0.9] for an 80% interval). None disables intervals. |
test_size |
int, float, str, Timestamp | Size or start of the test set, selecting the mode above. int: last test_size observations; float in (0, 1): last fraction of observations; str/Timestamp: first timestamp of the test set. None runs prediction mode. |
š” Tip
You can also use custom configurations for the forecaster, estimator, estimator_kwargs, lags, and window_features by passing them as arguments to forecast(). Other decisions have their own argument: metric, use_exog, differentiation, calendar_features, target_transformer and dropna_from_series. This allows you to override the assistant's automatic choices and use your own preferred settings. For example, this code specifies a custom forecaster while still letting the assistant handle the rest of the workflow:
results = assistant.forecast(
data = data,
target = 'users',
date_column = "date_time",
steps = 36,
test_size = 36,
forecaster = 'ForecasterFoundation'
)
The following code demonstrates how to execute the assistant in evaluation mode. By explicitly defining the test_size parameter (in this case, test_size=36), the pipeline automatically reserves the final 36 observations as a test set.
During execution, the assistant profiles the dataset, incorporates the provided exogenous features (holiday, weather, and temp), and trains an appropriate model on the training split. Because the method is triggered in evaluation mode, the resulting ForecastResult object provides the out-of-sample predictions, an 80% prediction interval, and the performance metrics evaluated against the held-out ground truth.
# Execute the forecasting assistant in evaluation mode
# ==============================================================================
results = assistant.forecast(
data = data,
target = 'users',
date_column = "date_time",
steps = 36,
interval = [0.1, 0.9], # 80% prediction interval
test_size = 36 # Last 36 hours as test set (evaluation mode)
)
# Inspect the performance metrics and the resulting predictions
# ==============================================================================
display(results.metrics)
display(results.predictions.head())
| mean_absolute_error | root_mean_squared_error | mean_absolute_scaled_error | mean_absolute_percentage_error | |
|---|---|---|---|---|
| 0 | 32.013374 | 52.524866 | 0.497185 | 0.415688 |
| pred | lower_bound | upper_bound | |
|---|---|---|---|
| 2012-12-30 12:00:00 | 146.512223 | 111.097550 | 181.185404 |
| 2012-12-30 13:00:00 | 138.768717 | 96.950185 | 178.804105 |
| 2012-12-30 14:00:00 | 145.133323 | 92.701496 | 185.332563 |
| 2012-12-30 15:00:00 | 140.891323 | 89.525337 | 185.272888 |
| 2012-12-30 16:00:00 | 139.538959 | 86.994814 | 180.904345 |
The show_code() method allows users to retrieve the exact code used to generate the forecast.
# skforecast code that generated the results
# ==============================================================================
results.show_code()
To generate forecasts for true future periods (starting immediately after the last observation in the dataset), the assistant is executed in prediction mode. This mode is active by default when test_size=None. In this configuration, the pipeline trains the optimal model using the entire available dataset and projects the predictions forward by the specified number of steps. Because there is no holdout data to serve as ground truth, the resulting ForecastResult object does not compute performance metrics. Additionally, if the historical data relies on exogenous features, a DataFrame containing their future values spanning the entire forecast horizon, or the path of a CSV file with them, must be explicitly supplied via the exog parameter.
# 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,
target = 'users',
date_column = "date_time",
steps = 36,
interval = [0.1, 0.9], # 80% prediction interval
test_size = None, # Use the entire dataset for training (prediction mode)
exog = exog # Future values of exogenous variables for the next 36 hours
)
display(results_pred.predictions.head())
| pred | lower_bound | upper_bound | |
|---|---|---|---|
| 2013-01-01 00:00:00 | 27.442927 | 11.127479 | 47.557452 |
| 2013-01-01 01:00:00 | 13.318240 | 3.310496 | 27.242435 |
| 2013-01-01 02:00:00 | 9.208553 | 2.380079 | 19.120340 |
| 2013-01-01 03:00:00 | 5.329501 | 0.570137 | 10.013675 |
| 2013-01-01 04:00:00 | 5.979160 | 1.305255 | 10.265962 |
Both modes return a ForecastResult, a lightweight container that bundles everything the assistant used and produced, so you can inspect the outputs, audit the decisions, or lift the code straight into production.
| Attribute | Type | Description |
|---|---|---|
predictions |
DataFrame | Forecasted values for the requested steps. When intervals (or quantiles) are requested, the bound columns are included alongside the point predictions. |
metrics |
DataFrame, 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, where there is no ground truth to score against. |
code |
str | The exact standalone skforecast script that produced the forecast, deterministic and ready to run on its own. |
profile |
ForecastingProfile |
The data profile behind the forecast: metadata, summary statistics, detected frequency, significant lags, and the high-level modeling decisions. |
plan |
ForecastPlan |
The detailed configuration that was executed: forecaster, estimator, lags, window features, preprocessing, and interval settings. |
Displaying the object in a notebook renders a rich summary of all of the above; the raw script is also available through results.show_code().
# 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, 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. ā ā ā ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā⯠Predictions (36 rows) āāāāāāāāāāāāāāāāāāāāāāā³āāāāāāāāāāā³āāāāāāāāāāāāāā³āāāāāāāāāāāāāā ā Index ā pred ā lower_bound ā upper_bound ā ā”āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā© ā 2013-01-01 00:00:00 ā 27.4429 ā 11.1275 ā 47.5575 ā āāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2013-01-01 01:00:00 ā 13.3182 ā 3.3105 ā 27.2424 ā āāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2013-01-01 02:00:00 ā 9.2086 ā 2.3801 ā 19.1203 ā āāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2013-01-01 03:00:00 ā 5.3295 ā 0.5701 ā 10.0137 ā āāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2013-01-01 04:00:00 ā 5.9792 ā 1.3053 ā 10.2660 ā āāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā ... ā ... ā ... ā ... ā āāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2013-01-02 07:00:00 ā 125.3912 ā 77.8800 ā 189.4169 ā āāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2013-01-02 08:00:00 ā 253.6618 ā 159.2711 ā 365.0444 ā āāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2013-01-02 09:00:00 ā 190.4495 ā 133.4486 ā 237.9817 ā āāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2013-01-02 10:00:00 ā 132.0387 ā 100.9730 ā 173.2996 ā āāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2013-01-02 11:00:00 ā 145.3529 ā 110.8851 ā 201.4766 ā āāāāāāāāāāāāāāāāāāāāāāā“āāāāāāāāāāā“āāāāāāāāāāāāāā“āāāāāāāāāāāāāā
Interpreting results¶
After executing the workflow, you can leverage the LLM reasoning layer to interpret the outputs. By passing the ForecastResult object to the ask() method as context, the assistant analyzes the generated predictions, performance metrics, and model configuration. This allows you to quickly extract actionable insights (such as contextualizing specific error metrics, identifying predicted trends, or diagnosing model behavior) directly in natural language.
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.
# Asking the assistant about the forecast results
# ==============================================================================
explanation = assistant.ask(
prompt = "Explain the results of the forecast, including the metrics and predictions.",
context = results
)
/var/folders/wt/8tvn563d5v55nspfbydgqb9r0000gp/T/ipykernel_86717/2239136354.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`. explanation = assistant.ask(
# Show the explanation generated by the LLM
# ==============================================================================
explanation.show_explanation()
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Assistant Response āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā® ā ā ā The forecast is a 36-step hold-out evaluation of ForecasterRecursive with ā ā LGBMRegressor, and its MASE of 0.497185 is below 1, so it beat the one-step naive ā ā forecast (repeat the previous value) on this window. The MAE is 32.013374 users per ā ā hour, set against a target mean of 187.8. Because this is a hold-out check on dates ā ā already in the data, it is not a forecast of the future. ā ā ā ā What was evaluated ā ā ā ā ⢠The model was trained on data up to 2012-12-30 11:00:00 and predicted the next 36 ā ā hourly steps, ending 2012-12-31 23:00:00. ā ā ⢠The plan uses 32 lags, window features (mean and std over 3 hours, mean over 24 ā ā hours, mean over 168 hours), and the exogenous columns holiday, weather and temp. ā ā Weather is categorical and handled automatically. ā ā ⢠The interval is [0.1, 0.9], an 80% nominal interval, built by bootstrapping. ā ā ā ā Metrics ā ā ā ā ⢠MAE: 32.013374. The average absolute miss, in users per hour. This is the primary ā ā metric of the plan. ā ā ⢠RMSE: 52.524866. Also in users per hour. I have no per-step errors, so I cannot ā ā say what drives the difference between RMSE and MAE. ā ā ⢠MASE: 0.497185. Below 1, so it beat the one-step naive forecast on this window. ā ā ⢠MAPE: 0.415688. This is a fraction, quoted as given. The target has a minimum of ā ā 1, so values near zero make MAPE unreliable here. Treat it with caution and rely ā ā on MAE and MASE. ā ā ā ā These scores come from a single 36-hour window. Per-fold results are not provided, ā ā so I cannot tell how stable they would be on other windows. ā ā ā ā Predictions ā ā ā ā Only the first 5 and last 5 of the 36 rows were provided, so I will not describe a ā ā trend across the horizon. Statements about the full set rely on the per-column ā ā summary: ā ā ā ā ⢠Point forecast (pred): ranges from a minimum of 5.258729928204422 to a maximum of ā ā 260.7711523801768, with a mean of 103.19879814283314. ā ā ⢠Lower bound: minimum 0.44880061218456635, maximum 142.57459533864323, mean ā ā 61.74293153975548. ā ā ⢠Upper bound: minimum 12.096545115409352, maximum 352.6076131902337, mean ā ā 137.95308075514998. ā ā ā ā For reference, the first predicted hour (2012-12-30 12:00:00) is 146.512223 with an ā ā interval of 111.097550 to 181.185404. The last hour (2012-12-31 23:00:00) is ā ā 39.970777 with an interval of 17.809739 to 59.555964. ā ā ā ā Caveats ā ā ā ā ⢠Observed values for the predicted rows are not shown, so I cannot say how many ā ā fell inside the 80% interval. Empirical coverage was not supplied, and I cannot ā ā confirm the interval is well calibrated. ā ā ⢠To measure accuracy over many windows, you could use assistant.backtest(). To ā ā check the choice of model against alternatives, you could use ā ā assistant.compare(). ā ā ā ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāÆ
Refining the modeling plan¶
Beyond explaining results, the assistant can also help you to improve the modeling strategy using the refine_plan() method. This method accepts an existing profile and plan and returns an updated ForecastPlan. It operates in two distinct modes:
Deterministic mode (Explicit Overrides): When no prompt is provided, you can pass explicit configuration overrides (such as
forecaster,estimator,estimator_kwargs,steps,interval,lags, orwindow_features). Only the explicitly specified fields are updated; the remaining configuration is deterministically re-derived from the original plan.LLM mode (Domain Knowledge Integration): When a prompt is provided, the assistant leverages the LLM to interpret your natural-language domain knowledge. The agent suggests domain-specific
lagsandwindow_features, which are then merged into the plan. To maintain strict interpretability, the LLMās reasoning is appended to the returned plan'sexplanationattribute, allowing you to trace exactly why each feature was proposed. 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 following example demonstrates the LLM mode. By supplying a prompt with context about the dataset, we instruct the assistant to engineer more appropriate lags and window features. We then execute forecast() using the refined plan and compare the new metrics against our original baseline run.
Keep in mind that a refined plan is a hypothesis, not a guaranteed improvement. The LLM proposes lags and window features from the domain knowledge you provide, but only a proper evaluation can confirm whether they actually help. Always compare the refined plan against the original before adopting it, and check that the suggested features are sensible for your data and use case rather than trusting them blindly.
# Ask the assistant to improve the forecast accuracy
# ==============================================================================
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."
)
refined_plan = assistant.refine_plan(
profile = results_pred.profile,
plan = results_pred.plan,
prompt = prompt
)
# Refined plan proposed by the assistant
# ==============================================================================
refined_plan
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', 'min', 'max'], '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)', 'min(window=24)', ā ā 'max(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: Recent hours (lags 1-6) capture the current trend and ā ā momentum. Lag 12 covers the half-day contrast between morning and evening rush-hour ā ā peaks. Lags 23-25 and 48 (plus 72, 96, 120, 144) anchor the daily rhythm, since the ā ā same hour on previous days is a strong predictor of the rush-hour shape. Lags ā ā 167-169 and 336 capture the weekly cycle, so the same hour last week and two weeks ā ā ago reflects the weekday/weekend pattern. Lag 24 and 48 are well suited to the ā ā 36-step horizon, which spans more than a full day. Window features: a short 3-hour ā ā mean/std tracks immediate level and volatility; a 24-hour mean/std/min/max ā ā summarises the last full day, including peak and trough levels that reflect ā ā rush-hour intensity; a 168-hour mean gives the weekly baseline level. Weekday vs ā ā weekend differences are best handled with calendar features (hour, day of week) on ā ā top of these lags. The noisy, sparse lag set was replaced by a structured one tied ā ā to daily and weekly cycles. ā ā ā ā Note: the LLM-suggested lags and window_features are hypotheses, not validated ā ā improvements. Confirm any expected accuracy gain before relying on them. ā ā ā ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāÆ
# Run the forecast with the refined plan
# ==============================================================================
results_refined = assistant.forecast(
data = data,
target = 'users',
date_column = "date_time",
steps = 36,
test_size = 36, # Last 36 hours as test set (evaluation mode)
plan = refined_plan # Refined plan proposed by the assistant
)
# Results of the forecast with the refined plan
# ==============================================================================
results_refined.metrics
| mean_absolute_error | root_mean_squared_error | mean_absolute_scaled_error | mean_absolute_percentage_error | |
|---|---|---|---|---|
| 0 | 28.328456 | 43.378029 | 0.439957 | 0.323751 |
# Results of the forecast with the original plan
# ==============================================================================
results.metrics
| mean_absolute_error | root_mean_squared_error | mean_absolute_scaled_error | mean_absolute_percentage_error | |
|---|---|---|---|---|
| 0 | 32.013374 | 52.524866 | 0.497185 | 0.415688 |
As noted above, a refined plan is a hypothesis, not a guaranteed improvement. The LLM may propose lags or window features that are not relevant to the series, or it may misread the domain knowledge you provided, so the refined plan can perform worse than the original.
More importantly, here we evaluate the change on a single 36-hour test window, which is far too small to draw a reliable conclusion. A single split can favor either plan by chance. To decide whether the refinement genuinely helps, evaluate both plans with a backtest over multiple folds (see the next section), which averages performance across many test windows and gives a far more trustworthy comparison.
Backtesting¶
In time series forecasting, backtesting is the process of evaluating a predictive model by retrospectively simulating its performance on historical data. It functions as a specialized form of temporal cross-validation, ensuring that data leakage is prevented by strictly respecting the chronological order of observations.
The reliability of backtesting metrics depends entirely on how closely the evaluation setup mirrors production conditions. To obtain trustworthy performance estimates, the backtesting strategy must accurately reflect the real-world prediction horizon, refit frequency, and data availability.
In skforecast-ai, this validation strategy is governed by the TimeSeriesFold object. It defines exactly how the historical data is partitioned into successive training and test windows. It controls critical parameters such as the forecast horizon (steps), the starting point for evaluation (initial_train_size), and whether the model is periodically retrained as the window rolls forward (refit). Because these choices dictate the interpretation of the resulting metrics, correctly configuring the TimeSeriesFold is the most critical decision in the evaluation phase. For a comprehensive overview of these mechanics, refer to the skforecast Backtesting user guide.
skforecast-ai provides three distinct ways to define this validation strategy, ranging from full manual control to automated generation:
Explicit Instantiation (Recommended): Manually construct a
TimeSeriesFoldand pass it directly to thebacktest()method. If you already know the exact operational constraints of your production environment, this is the most explicit and reproducible approach, keeping the validation setup entirely under your control.LLM Mode (
create_cv()with a prompt): Describe your operational use case in natural language (e.g., required horizon, retraining frequency, trusted historical depth). The LLM reasoning layer interprets this context and translates it into a strictly definedTimeSeriesFold, materializing the setup into deterministic code.Deterministic Mode (
create_cv()without a prompt): Allow the assistant to automatically derive a sensibleTimeSeriesFoldfrom the existing profile and plan using rule-based defaults. You can still explicitly override individual parameters such asinitial_train_sizeorrefitas needed.
The animation below shows the LLM mode with a deployment scenario: how the scenario becomes TimeSeriesFold parameters (the horizon always comes from the plan), and how backtest() then evaluates the model fold by fold, the way it will be used.
The following example demonstrates the three approaches.
# Explicit Instantiation of the cv
# ==============================================================================
# Create your own TimeSeriesFold object
end_train = '2012-08-31 23:59:00'
cv = TimeSeriesFold(
steps = 36,
initial_train_size = end_train,
refit = False
)
results_backtest = assistant.backtest(
data = data,
target = 'users',
date_column = "date_time",
cv = cv, # TimeSeriesFold, or a CVResult from create_cv()
interval = [0.1, 0.9], # 80% prediction interval
)
/var/folders/wt/8tvn563d5v55nspfbydgqb9r0000gp/T/ipykernel_86717/3423804962.py:11: IntervalCoverageWarning: The prediction interval [0.1, 0.9] has a nominal coverage of 80 %, but only 65.5 % 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(
# Show backtest results
# ==============================================================================
results_backtest.show_explanation()
display(results_backtest.metrics)
display(results_backtest.predictions.head())
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā 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: ā ā 46.3122, root_mean_squared_error: 74.1342, mean_absolute_scaled_error: 0.7290, ā ā mean_absolute_percentage_error: 0.4727. They are measured on 2928 predictions with ā ā an observed value (n_evaluated). Prediction interval [0.1, 0.9] (nominal coverage 80 ā ā %): 65.5 % of the 2928 actual values fell inside it (coverage: 0.6547), with a mean ā ā width of 90.3602 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 | 46.312218 | 74.134214 | 0.729017 | 0.472735 | 0.654713 | 90.360228 | 2928 |
| fold | step | y_true | pred | lower_bound | upper_bound | |
|---|---|---|---|---|---|---|
| 2012-09-01 00:00:00 | 0 | 1 | 168.0 | 124.163668 | 99.669766 | 149.384335 |
| 2012-09-01 01:00:00 | 0 | 2 | 79.0 | 96.989454 | 68.523139 | 127.651105 |
| 2012-09-01 02:00:00 | 0 | 3 | 69.0 | 65.894182 | 32.969786 | 97.883129 |
| 2012-09-01 03:00:00 | 0 | 4 | 35.0 | 29.961028 | 10.347714 | 60.808462 |
| 2012-09-01 04:00:00 | 0 | 5 | 12.0 | 9.103018 | 2.980393 | 28.085362 |
After running the workflow, you can ask the assistant to explain the backtesting results. The ask() method can take a BacktestResult object as context and provide insights about the strategy, the metrics, or any other relevant information.
# Asking the assistant about the backtesting
# ==============================================================================
explanation = assistant.ask(
prompt = "Explain the results of the backtesting, including the strategy, metrics, and predictions.",
context = results_backtest
)
/var/folders/wt/8tvn563d5v55nspfbydgqb9r0000gp/T/ipykernel_86717/244763278.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`. explanation = assistant.ask(
# Show the explanation generated by the LLM
# ==============================================================================
explanation.show_explanation()
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Assistant Response āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā® ā ā ā The model beat the one-step naive forecast on this backtest: MASE is 0.7290, below ā ā 1. The 80% prediction interval was too narrow, though, since only 0.6547 of the ā ā observed values fell inside it. ā ā ā ā Strategy ā ā ā ā ⢠ForecasterRecursive with LGBMRegressor predicts a 36-step horizon (hourly data, ā ā target users). ā ā ⢠The model was trained once on data up to 2012-08-31 23:59:00 and was not refit ā ā (refit: False, n_fits: 1). The fixed training window setting therefore has no ā ā practical effect. ā ā ⢠There are 82 folds with a stride of 36 and no gap. The last fold has only 12 ā ā steps. ā ā ⢠Metrics are computed on 2928 predictions with an observed value (n_evaluated). ā ā ⢠Intervals are 80% nominal (quantiles 0.1 and 0.9) and come from bootstrapping. ā ā ā ā Metrics ā ā ā ā ⢠MAE: 46.3122. This is the primary metric, in the units of users. For context, the ā ā target's mean is 187.8 and its standard deviation is 181.3 over the full dataset. ā ā ⢠RMSE: 74.1342. It is in the same units as the target. ā ā ⢠MASE: 0.7290. Below 1 means the model beat the one-step naive forecast (repeat ā ā the previous value). ā ā ⢠MAPE: 0.4727. This is a fraction, quoted as given. It has little meaning when the ā ā target takes values at or around zero, and users has a minimum of 1, so I would ā ā not lean on it. ā ā ⢠Coverage: 0.6547 against the nominal 80%. The intervals missed more observed ā ā values than intended, so they appear too narrow. ā ā ⢠Interval width: 90.3602 on average, in the units of the target. ā ā ā ā Predictions ā ā ā ā Only the first 5 and last 5 of the 2928 rows were provided, so I cannot describe how ā ā the forecasts behave across the horizon. The full-set summary says: ā ā ā ā ⢠Predictions range from a minimum of 1.9345 to a maximum of 881.3579, with a mean ā ā of 235.9997. ā ā ⢠The lower bound has a minimum of -2.1352, which is below the target's observed ā ā minimum of 1. The bootstrapped intervals can therefore extend into values users ā ā cannot take. ā ā ⢠The upper bound reaches a maximum of 914.3773. ā ā ā ā Caveats ā ā ā ā ⢠Per-fold results are not provided, so I cannot say how stable the error is across ā ā the 82 folds or whether differences from other candidates would be meaningful. ā ā ⢠The y_true values were not sent, so I cannot check the individual predictions ā ā against observations. ā ā ā ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāÆ
Rather than manually configuring TimeSeriesFold parameters, you can describe your target backtesting strategy in natural language and allow the assistant's LLM layer to translate it into a rigorous cross-validation schema. Once you have generated a data profile and a modeling plan, simply pass a prompt detailing your operational constraints, such as the required forecast horizon, historical training depth, refitting frequency, or expected data gaps. The assistant processes this context and returns a fully configured TimeSeriesFold object, accompanied by an explicit explanation of its design choices. This transparency ensures you can thoroughly audit and verify the validation strategy before executing the backtest.
# Let the assistant create the cross-validation strategy for you
# ==============================================================================
# Profile and create a plan for your data
profile = assistant.profile(data, target="users", date_column="date_time")
plan = assistant.plan(profile, steps=36)
# Call create_cv with a prompt that describes your prediction strategy
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 = assistant.create_cv(
profile = profile,
plan = plan,
prompt = prompt
)
# CVResult object: the TimeSeriesFold, its explanation and the code that rebuilds it
# ==============================================================================
cv
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Cross-Validation Explanation āāāāāāāāāāāāāāāāāāāāāāāāāāāāāā® ā ā ā The user wants the model trained once on all data up to the end of August 2012. With ā ā hourly data, the last training timestamp is 2012-08-31 23:00:00, so I use that as ā ā the date string. It lies strictly inside the dataset range (2011-01-01 to 2012-12-31 ā ā 23:00). That gives roughly openly 14,600 training observations, far above the ā ā minimum viable size of 373. About 2,928 hours (September to December 2012) remain ā ā for testing. With 36-step folds that is about 81 folds, well over the required 2. ā ā refit=False matches the instruction not to refit as the window rolls forward. ā ā fixed_train_size has no effect without refit, so I leave it at its default. The ā ā scenario mentions no deployment delay, so gap stays 0. fold_stride and skip_folds ā ā stay at their defaults, giving non-overlapping 36-hour test blocks. Initial training ā ā up to 2012-08-31 23:00:00, 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 ā 2012-08-31 23:00: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 Reasoning
# ==============================================================================
import textwrap
print(textwrap.fill(cv.explanation, width=88))
The user wants the model trained once on all data up to the end of August 2012. With hourly data, the last training timestamp is 2012-08-31 23:00:00, so I use that as the date string. It lies strictly inside the dataset range (2011-01-01 to 2012-12-31 23:00). That gives roughly openly 14,600 training observations, far above the minimum viable size of 373. About 2,928 hours (September to December 2012) remain for testing. With 36-step folds that is about 81 folds, well over the required 2. refit=False matches the instruction not to refit as the window rolls forward. fixed_train_size has no effect without refit, so I leave it at its default. The scenario mentions no deployment delay, so gap stays 0. fold_stride and skip_folds stay at their defaults, giving non- overlapping 36-hour test blocks. Initial training up to 2012-08-31 23:00:00, 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 object returned by create_cv() is equivalent to the one we built manually above (the same 82 folds; the timestamp is aligned to the hourly frequency). However, it was derived from a natural-language description rather than explicit parameters. The returned CVResult carries the splitter as cv.cv and, as cv.explanation, a description of the choices the assistant made. This allows you to verify that the resulting TimeSeriesFold matches your intended strategy.
The backtesting workflow returns a BacktestResult, a lightweight container that bundles everything the assistant used and produced, so you can inspect the outputs, audit the decisions, or lift the code straight into production.
| Attribute | Type | Description |
|---|---|---|
predictions |
DataFrame | Full out-of-sample backtest predictions across all folds. When intervals (or quantiles) are requested, the bound columns are included alongside the point predictions. |
metrics |
DataFrame | Backtesting metrics (mean_absolute_error, root_mean_squared_error, mean_absolute_scaled_error, mean_absolute_percentage_error) returned by skforecast, one row per series, computed across all folds. |
cv_config |
dict | The resolved TimeSeriesFold parameters (steps, initial train size, refit, gap, etc.), kept for full traceability of the validation strategy. |
code |
str | The exact standalone skforecast script that reproduces the backtesting workflow, deterministic and ready to run on its own. |
explanation |
str | A human-readable summary of the backtesting configuration and what the results mean. |
profile |
ForecastingProfile |
The data profile behind the backtest: metadata, summary statistics, detected frequency, significant lags, and the high-level modeling decisions. |
plan |
ForecastPlan |
The detailed configuration that was executed: forecaster, estimator, lags, window features, preprocessing, and interval settings. |
Displaying the object renders a rich summary of all of the above; the raw script is also available through results_backtest.show_code().
# 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: ā ā 46.3122, root_mean_squared_error: 74.1342, mean_absolute_scaled_error: 0.7290, ā ā mean_absolute_percentage_error: 0.4727. They are measured on 2928 predictions with ā ā an observed value (n_evaluated). Prediction interval [0.1, 0.9] (nominal coverage 80 ā ā %): 65.5 % of the 2928 actual values fell inside it (coverage: 0.6547), with a mean ā ā width of 90.3602 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⦠ā ā”āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā© ā 46.3122 ā 74.1342 ā 0.7290 ā 0.4727 ā 0.6547 ā 90.3602 ā 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 ā 124.1637 ā 99.6698 ā 149.3843 ā ā 00:00:00 ā ā ā ā ā ā ā āāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2012-09-01 ā 0.0000 ā 2.0000 ā 79.0000 ā 96.9895 ā 68.5231 ā 127.6511 ā ā 01:00:00 ā ā ā ā ā ā ā āāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2012-09-01 ā 0.0000 ā 3.0000 ā 69.0000 ā 65.8942 ā 32.9698 ā 97.8831 ā ā 02:00:00 ā ā ā ā ā ā ā āāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2012-09-01 ā 0.0000 ā 4.0000 ā 35.0000 ā 29.9610 ā 10.3477 ā 60.8085 ā ā 03:00:00 ā ā ā ā ā ā ā āāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2012-09-01 ā 0.0000 ā 5.0000 ā 12.0000 ā 9.1030 ā 2.9804 ā 28.0854 ā ā 04:00:00 ā ā ā ā ā ā ā āāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā ... ā ... ā ... ā ... ā ... ā ... ā ... ā āāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2012-12-31 ā 81.0000 ā 8.0000 ā 119.0000 ā 145.8848 ā 97.1293 ā 180.5958 ā ā 19:00:00 ā ā ā ā ā ā ā āāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2012-12-31 ā 81.0000 ā 9.0000 ā 89.0000 ā 103.3326 ā 67.3546 ā 140.2631 ā ā 20:00:00 ā ā ā ā ā ā ā āāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2012-12-31 ā 81.0000 ā 10.0000 ā 90.0000 ā 64.1944 ā 33.2954 ā 86.5947 ā ā 21:00:00 ā ā ā ā ā ā ā āāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2012-12-31 ā 81.0000 ā 11.0000 ā 61.0000 ā 46.9473 ā 23.0095 ā 64.8209 ā ā 22:00:00 ā ā ā ā ā ā ā āāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāāāāā¼āāāāāāāāāāāāā⤠ā 2012-12-31 ā 81.0000 ā 12.0000 ā 49.0000 ā 30.5361 ā 12.3134 ā 45.8523 ā ā 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, 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. ā ā ā ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāÆ
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.
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 animation below shows automatic candidates with the strategy of the backtesting example: the three configurations the profile proposes and the seasonal naive baseline run through the same folds, the leaderboard is a plain sort of the metric, and the winner goes straight into forecast(). Finally, ask() explains the ranking without changing it.
The following examples demonstrate both approaches.
š” 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.
# Comparison of the forecaster candidates suggested by the profile
# ==============================================================================
end_train = '2012-08-31 23:59:00'
cv = TimeSeriesFold(
steps = 36,
initial_train_size = end_train,
refit = False,
)
results_compare = assistant.compare(
data = data,
target = 'users',
date_column = "date_time",
cv = cv, # Same TimeSeriesFold for every candidate
candidates = None # Candidates suggested by the assistant
)
# 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%. ā ā ā ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāÆ
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 dataset 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.
# Comparison of an explicit shortlist of configurations
# ==============================================================================
candidates = [
(
"ridge_baseline",
{
"forecaster": "ForecasterRecursive",
"estimator" : "Ridge",
"lags" : 24,
}
),
(
"lgbm_daily_lags",
{
"forecaster": "ForecasterRecursive",
"estimator" : "LGBMRegressor",
"lags" : 24,
}
),
(
"lgbm_weekly_lags_rolling",
{
"forecaster" : "ForecasterRecursive",
"estimator" : "LGBMRegressor",
"lags" : [1, 2, 3, 23, 24, 25, 167, 168, 169],
"window_features" : [{"stats": ["mean", "std"], "window_size": 24}],
}
),
(
"lgbm_direct",
{
"forecaster": "ForecasterDirect",
"estimator" : "LGBMRegressor",
"lags" : 24,
}
),
(
"foundation_model",
{
"forecaster": "ForecasterFoundation"
}
),
]
results_compare = assistant.compare(
data = data,
target = 'users',
date_column = "date_time",
cv = cv,
candidates = candidates, # Specific candidates to compare
metric = ['mean_absolute_error', 'mean_absolute_scaled_error'],
)
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 | lgbm_direct | ForecasterDirect | LGBMRegressor | 50.224908 | 0.790885 | 2928 |
| 2 | 3 | lgbm_weekly_lags_rolling | ForecasterRecursive | LGBMRegressor | 50.557647 | 0.795684 | 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 |
The comparison returns a ComparisonResult, which groups the shared setup, ranked leaderboard, and individual backtests in a single object. Use it to inspect the results, audit the comparison, or reuse the winning candidateās code in production.
| 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). |
Displaying the object renders a rich summary of the explanation and the leaderboard.
# Rich summary of the comparison
# ==============================================================================
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, 23.5% ahead of ā ā 'lgbm_direct' (50.2249). 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 ā lgbm_dir⦠ā Forecast⦠ā LGBMRegr⦠ā 50.2249 ā 0.7909 ā 2928 ā āāāāāāāāā¼āāāāāāā¼āāāāāāāāāāāā¼āāāāāāāāāāāā¼āāāāāāāāāāāā¼āāāāāāāāāāāāā¼āāāāāāāāāāāā¼āāāāāāāāāāāā⤠ā 2 ā 3 ā lgbm_wee⦠ā Forecast⦠ā LGBMRegr⦠ā 50.5576 ā 0.7957 ā 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 ā āāāāāāāāā“āāāāāāā“āāāāāāāāāāāā“āāāāāāāāāāāā“āāāāāāāāāāāā“āāāāāāāāāāāāā“āāāāāāāāāāāā“āāāāāāāāāāāāā
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 |
The most useful result of a comparison is often not the leaderboard, but best_candidate. It is a complete BacktestResult containing both the winning profile and plan, so it can be passed directly into the rest of the 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
# ==============================================================================
# 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,
target = 'users',
date_column = "date_time",
steps = 36,
profile = results_compare.profile,
plan = results_compare.best_candidate.plan,
interval = [0.1, 0.9], # 80% prediction interval
test_size = None, # Use the entire dataset for training (prediction mode)
exog = exog # Future values of exogenous variables for the next 36 hours
)
# Reproducible skforecast script for the winning configuration
# ==============================================================================
results_pred.show_code()
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.
# Asking the assistant about the comparison
# ==============================================================================
explanation = assistant.ask(
prompt = (
"Explain the comparison results. Is the margin between the top candidates "
"meaningful, or are they practically equivalent?"
),
context = results_compare
)
/var/folders/wt/8tvn563d5v55nspfbydgqb9r0000gp/T/ipykernel_86717/955099911.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`. explanation = assistant.ask(
# Show the explanation generated by the LLM
# ==============================================================================
explanation.show_explanation()
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā Assistant Response āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā® ā ā ā The ranking is clear, but the context does not let me say whether the margins are ā ā meaningful. Per-fold errors are not provided, so I cannot judge how much of any gap ā ā is fold-to-fold noise. The top candidate, foundation_model, has the lowest ā ā mean_absolute_error. The next two candidates are very close to each other on that ā ā metric. ā ā ā ā What the leaderboard shows ā ā ā ā All six candidates were scored on the same 2928 predictions across 82 folds (36-step ā ā horizon, last fold 12 steps), ranked by mean_absolute_error (lower is better): ā ā ā ā ⢠Rank 1: foundation_model (ForecasterFoundation, autogluon/chronos-2-small), ā ā 38.436159 ā ā ⢠Rank 2: lgbm_direct (ForecasterDirect, LGBMRegressor), 50.224908 ā ā ⢠Rank 3: lgbm_weekly_lags_rolling (ForecasterRecursive, LGBMRegressor), 50.557647 ā ā ⢠Rank 4: lgbm_daily_lags (ForecasterRecursive, LGBMRegressor), 55.517689 ā ā ⢠Rank 5: Baseline (seasonal naive), 91.668716 ā ā ⢠Rank 6: ridge_baseline (ForecasterRecursive, Ridge), 93.145620 ā ā ā ā Are the top candidates equivalent? ā ā ā ā ⢠Rank 1 vs rank 2: foundation_model has the lower mean_absolute_error. Without ā ā per-fold spread, I cannot say whether that gap would hold across different folds ā ā or periods. ā ā ⢠Rank 2 vs rank 3: lgbm_direct (50.224908) and lgbm_weekly_lags_rolling ā ā (50.557647) are listed in that order, but the context gives no way to tell ā ā whether their difference is meaningful. I will not treat the order between them ā ā as established. ā ā ⢠Rank 3 vs rank 4: the same limitation applies; no spread information is ā ā available. ā ā ā ā Reading MASE ā ā ā ā ⢠foundation_model has a mean_absolute_scaled_error of 0.605517, below 1, so it ā ā beats the one-step naive forecast. ā ā ⢠lgbm_direct (0.790885), lgbm_weekly_lags_rolling (0.795684) and lgbm_daily_lags ā ā (0.874763) are also below 1. ā ā ⢠Baseline (seasonal naive) (1.445666) and ridge_baseline (1.468844) are above 1, ā ā so they do not beat the one-step naive forecast. ā ā ⢠On mean_absolute_error, ridge_baseline ranks below the Baseline (seasonal naive) ā ā row, so it does not beat that reference. ā ā ā ā Caveat on how the candidates were evaluated ā ā ā ā ForecasterFoundation is not trained. Its backtest uses only the folds, and each fold ā ā forecasts from the observations before it. The other candidates were trained once ā ā with no refit. I cannot say whether this difference affects the comparison. ā ā ā ā Possible next steps ā ā ā ā ⢠assistant.backtest() measures accuracy for a single candidate. ā ā ⢠assistant.compare() re-runs the candidate comparison, for example if you want to ā ā repeat it on different folds. ā ā ā ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāÆ
This tutorial covered the fast path of skforecast-ai: the most efficient route from raw time series data to a validated forecast with minimal manual configuration. This approach is highly effective for rapidly generating robust baseline models when you trust the assistant to implement sensible default strategies.
However, if your use case requires granular control to inspect, audit, or modify the intermediate objects (such as the data profile, the modeling plan, or the validation schema) before executing the next phase, we recommend exploring the step-by-step workflow for a comprehensive, stage-by-stage walkthrough of the underlying architecture.