Results
skforecast_ai.schemas.results ¶
Classes:
| Name | Description |
|---|---|
RenderedScript |
Structured representation of a rendered forecasting script. |
LLMContext |
Everything |
ExplainableResult |
Capability shared by every result that can describe itself to an LLM. |
CodeGenerationResult |
Result of the |
SingleRunResult |
Shared base for the result of a single forecasting or backtesting run. |
ForecastResult |
Result of the |
BacktestResult |
Result of the |
AskResult |
Result of the |
CandidateFailure |
Reason why a single |
ComparisonResult |
Result of the |
Classes¶
RenderedScript ¶
Bases: BaseModel
Structured representation of a rendered forecasting script.
Splits the rendered script into logical sections so that
forecast() can exec the core logic while forecast_code()
returns the full standalone script.
Attributes:
| Name | Type | Description |
|---|---|---|
imports |
str
|
Import statements required by the script. |
data_loading |
str
|
Code that loads data from CSV and sets up the index. |
core |
str
|
Core execution logic (preprocessing, split, fit, predict,
metrics). Operates on a pre-existing |
LLMContext ¶
Bases: BaseModel
Everything ask() needs in order to explain a result object.
Produced by ExplainableResult._build_llm_context. Keeping the four
fields in a single object means ask() never reads a result's own
attributes, so a new kind of result can be explained without touching
ask().
Attributes:
| Name | Type | Description |
|---|---|---|
text |
str
|
Rendered plain-text context block inserted into the user message. |
profile |
ForecastingProfile, default None
|
Profile echoed back on |
plan |
ForecastPlan, default None
|
Plan echoed back on |
code |
str, default None
|
Generated script echoed back on |
ExplainableResult ¶
Capability shared by every result that can describe itself to an LLM.
Mirrors DisplayMixin, which lets a result describe itself to a
terminal. Subclasses must implement _build_llm_context, returning
the context block plus the artifacts ask() echoes back on its
AskResult.
Each result decides its own payload, so an aggregate result (for
example ComparisonResult) can send a compact summary instead of the
concatenated payloads of everything it wraps.
Methods:
| Name | Description |
|---|---|
to_llm_context |
Build the LLM context for this result. |
Functions¶
_build_llm_context ¶
_build_llm_context(*, send_data)
Source code in skforecast_ai/schemas/results.py
107 108 109 110 111 112 | |
to_llm_context ¶
to_llm_context(*, send_data=False)
Build the LLM context for this result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
send_data
|
bool
|
Whether raw data values may be included. When False, only
aggregate statistics are shown for row-level data. The
decision belongs to the caller, so the privacy policy stays
owned by |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
context |
LLMContext
|
Rendered context block plus the artifacts |
Source code in skforecast_ai/schemas/results.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
CodeGenerationResult ¶
Bases: DisplayMixin, BaseModel
Result of the forecast_code workflow.
Attributes:
| Name | Type | Description |
|---|---|---|
profile |
ForecastingProfile
|
Profile of the input dataset and high-level modeling decisions. |
plan |
ForecastPlan
|
Detailed forecasting plan. |
code |
str
|
Generated Python script. |
SingleRunResult ¶
Bases: DisplayMixin, ExplainableResult, BaseModel
Shared base for the result of a single forecasting or backtesting run.
Declares the fields that every single run produces, and renders them
into an LLM context block through _build_llm_context. Concrete
results (for example ForecastResult and BacktestResult) inherit
from this class and add the fields specific to them.
Aggregate results that wrap several runs (for example
ComparisonResult) do not inherit from this class; they implement
ExplainableResult directly so they can send a compact summary rather
than a concatenation of everything they wrap.
Attributes:
| Name | Type | Description |
|---|---|---|
profile |
ForecastingProfile
|
Profile of the input dataset and high-level modeling decisions. |
plan |
ForecastPlan
|
Detailed forecasting plan that was executed. |
code |
str
|
Generated Python script equivalent to the execution. |
predictions |
pandas DataFrame
|
Forecasted values produced by the run. |
metrics |
pandas DataFrame
|
Evaluation metrics produced by the run. |
Attributes¶
model_config
class-attribute
instance-attribute
¶
model_config = ConfigDict(arbitrary_types_allowed=True)
Functions¶
_build_llm_context ¶
_build_llm_context(*, send_data)
Describe a single run to the LLM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
send_data
|
bool
|
Whether raw prediction values may be included. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
context |
LLMContext
|
Context block covering the profile, plan, cross-validation configuration, deterministic summary, metrics, and predictions of this run. |
Source code in skforecast_ai/schemas/results.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
ForecastResult ¶
Bases: SingleRunResult
Result of the forecast workflow (executes the pipeline end-to-end).
Attributes:
| Name | Type | Description |
|---|---|---|
profile |
ForecastingProfile
|
Profile of the input dataset and high-level modeling decisions. |
plan |
ForecastPlan
|
Detailed forecasting plan that was executed. |
code |
str
|
Generated Python script equivalent to the execution. |
metrics |
pandas DataFrame, None
|
Evaluation metrics. DataFrame with columns
|
predictions |
pandas DataFrame
|
Forecasted values for the requested steps. When prediction intervals (or quantiles) are requested, the corresponding bound columns are included alongside the point predictions. |
Functions¶
_rich_body ¶
_rich_body(console, options)
Source code in skforecast_ai/schemas/results.py
278 279 280 281 282 283 284 285 | |
BacktestResult ¶
Bases: SingleRunResult
Result of the backtest workflow.
Attributes:
| Name | Type | Description |
|---|---|---|
profile |
ForecastingProfile
|
Profile of the input dataset and high-level modeling decisions. |
plan |
ForecastPlan
|
Detailed forecasting plan that was executed. |
cv_config |
dict
|
Resolved |
metrics |
pandas DataFrame
|
Backtesting metric values returned by skforecast. |
predictions |
pandas DataFrame
|
Full backtest predictions across all folds. |
code |
str
|
Generated Python script reproducing the backtesting workflow. |
explanation |
str
|
Human-readable explanation of the backtesting configuration and results summary. |
Attributes¶
Functions¶
_rich_body ¶
_rich_body(console, options)
Source code in skforecast_ai/schemas/results.py
317 318 319 320 321 322 323 324 325 | |
AskResult ¶
Bases: DisplayMixin, BaseModel
Result of the ask workflow (requires LLM).
Attributes:
| Name | Type | Description |
|---|---|---|
profile |
ForecastingProfile, default None
|
Profile of the input dataset and high-level modeling decisions, if data was provided. |
plan |
ForecastPlan, default None
|
Detailed forecasting plan, if the agent produced one. |
code |
str, default None
|
Generated Python script, if the agent produced one. |
explanation |
str
|
LLM-generated explanation or response. |
CandidateFailure ¶
Bases: BaseModel
Reason why a single compare() candidate failed to run.
Holds a plain-data snapshot of the failure instead of the live
exception. An exception object keeps its traceback frames alive, and
those frames reference the execution namespace (which contains a copy
of the dataset, the fitted forecaster and the predictions), so
retaining one per failed candidate would pin an unbounded amount of
memory. The formatted traceback carries the same debugging
information at a fixed, small cost, and keeps ComparisonResult
serializable.
Attributes:
| Name | Type | Description |
|---|---|---|
error_type |
str
|
Class name of the root-cause exception, for example
|
message |
str
|
Message of the root-cause exception. |
traceback |
str
|
Full formatted traceback of the failure. |
generated_code |
str, default None
|
Generated script that failed, when the failure happened while
executing rendered code. |
Methods:
| Name | Description |
|---|---|
from_exception |
Build a |
summary |
Build a concise one-line |
Attributes¶
Functions¶
from_exception
classmethod
¶
from_exception(exc)
Build a CandidateFailure from the exception a candidate raised.
A ForecastExecutionError wraps the generated code and the
formatted execution traceback; it is unwrapped to its
original_error root cause so the failure reports the underlying
reason rather than the verbose execution-context message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exc
|
Exception
|
Exception raised while evaluating a candidate. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
failure |
CandidateFailure
|
Plain-data snapshot of the failure. |
Source code in skforecast_ai/schemas/results.py
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | |
summary ¶
summary(max_length=200)
Build a concise one-line "ErrorType: message" summary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_length
|
int
|
Maximum length of the returned summary. Longer summaries are truncated with a trailing ellipsis. |
200
|
Returns:
| Name | Type | Description |
|---|---|---|
summary |
str
|
Single-line summary of the failure. |
Source code in skforecast_ai/schemas/results.py
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 | |
ComparisonResult ¶
Bases: DisplayMixin, ExplainableResult, BaseModel
Result of the compare workflow (ranks several forecasters).
Backtests several forecaster/estimator configurations with the same
cross-validation strategy and returns a metric-ranked leaderboard
plus the winning configuration as a reusable BacktestResult.
Attributes:
| Name | Type | Description |
|---|---|---|
profile |
ForecastingProfile
|
Shared profile used for every candidate. |
cv_config |
dict
|
Resolved |
results |
pandas DataFrame
|
Ranked comparison table, one row per candidate sorted best to
worst by |
candidates |
dict
|
Mapping of candidate name to the full |
failures |
dict
|
Mapping of candidate name to a |
ranking_metric |
str
|
Name of the metric used to sort |
explanation |
str
|
Human-readable summary of the comparison. |
best_name |
str
|
Name of the top-ranked candidate. |
best_candidate |
BacktestResult
|
Top-ranked candidate. Always present: a comparison in which every
candidate fails raises |
Notes
Every candidate name appears in exactly one of candidates and
failures, never in both and never in neither. The two mappings
therefore partition the candidates that were evaluated, and their
union matches the 'name' column of results.
best_name and best_candidate are plain properties rather than
fields, so the winning BacktestResult is not serialized a second
time by model_dump().
Attributes¶
model_config
class-attribute
instance-attribute
¶
model_config = ConfigDict(arbitrary_types_allowed=True)
Functions¶
_build_llm_context ¶
_build_llm_context(*, send_data)
Describe the comparison to the LLM.
Sends the leaderboard, the shared profile and cross-validation
strategy, one line per failure, and the winning candidate's plan.
The non-winning candidates' plans, code, and predictions are
withheld: the leaderboard already carries the numbers a ranking
question needs, so the payload does not grow with the number of
candidates. A specific candidate can still be explained by passing
candidates['<name>'] to ask() directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
send_data
|
bool
|
Whether raw data values may be included. Has no effect here:
a comparison renders aggregated leaderboard metrics only,
never row-level predictions. The parameter is part of the
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
context |
LLMContext
|
Context block for the comparison. The echoed |
Source code in skforecast_ai/schemas/results.py
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 | |
_rich_body ¶
_rich_body(console, options)
Source code in skforecast_ai/schemas/results.py
574 575 576 577 578 | |