RootMeanSquaredScaledError¶
yohou.metrics.RootMeanSquaredScaledError
¶
Bases: BasePointScorer
Root Mean Squared Scaled Error metric for point forecasts.
Computes RMSE scaled by the in-sample naive seasonal forecast error. This provides a scale-independent metric that enables comparison across time series with different magnitudes. Requires training data to compute scaling factors.
The RootMeanSquaredScaledError is defined as:
where the scale is the mean squared seasonal-naive error computed from training data as:
with \(m\) = seasonality, \(T\) = training length, \(h\) = forecast horizon, and \(j\) = column index. Per-column RootMeanSquaredScaledError values are averaged to produce the final score.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
seasonality
|
int
|
Seasonal period for computing scaling factors. Must be at least 1. Common values: 1 (non-seasonal), 7 (weekly), 12 (monthly), 24 (hourly daily pattern). |
1
|
aggregation_method
|
list of str or str
|
Dimensions to aggregate over. Options: - "stepwise": Aggregate across forecasting steps. - "vintagewise": Aggregate across vintages (observed times). - "componentwise": Aggregate across components, return per-timestep DataFrame - "groupwise": Aggregate across panel groups (panel data only) - "all": Aggregate across all dimensions (returns scalar). Same as ["stepwise", "vintagewise", "componentwise", "groupwise"]. Example outputs: - ["stepwise", "vintagewise"]: Per-component (and per-group) DataFrame. - "componentwise" or ["componentwise"]: Per-timestep (and per-group) DataFrame. - "groupwise" or ["groupwise"]: Per-component per-timestep DataFrame (panel aggregated). - ["stepwise", "vintagewise", "componentwise"]: Scalar (global) or per-group DataFrame (panel). - "all": Scalar float (hierarchically aggregated for panel data). |
"all"
|
groups
|
list of str, dict of str to float, or None
|
Panel group filter (list) or filter with weights (dict). |
None
|
components
|
list of str, dict of str to float, or None
|
Component filter (list) or filter with weights (dict). |
None
|
Attributes ¶
| Name | Type | Description |
|---|---|---|
lower_is_better |
bool
|
Always True for RootMeanSquaredScaledError. |
scales_ |
dict[str, float]
|
Fitted per-column scaling factors. Computed during fit() from training data naive seasonal forecast errors. |
Examples ¶
>>> import polars as pl
>>> from datetime import datetime, timedelta
>>> from yohou.metrics import RootMeanSquaredScaledError
>>> # Training data
>>> y_train = pl.DataFrame({
... "time": [datetime(2020, 1, 1) + timedelta(days=i) for i in range(10)],
... "value": [10.0, 12.0, 11.0, 13.0, 12.0, 14.0, 13.0, 15.0, 14.0, 16.0],
... })
>>> # Test predictions
>>> y_true = pl.DataFrame({
... "time": [datetime(2020, 1, 11), datetime(2020, 1, 12)],
... "value": [15.0, 17.0],
... })
>>> y_pred = pl.DataFrame({
... "vintage_time": [datetime(2020, 1, 10)] * 2,
... "time": [datetime(2020, 1, 11), datetime(2020, 1, 12)],
... "value": [15.5, 16.5],
... })
>>> rmsse = RootMeanSquaredScaledError(seasonality=2)
>>> rmsse.fit(y_train)
RootMeanSquaredScaledError(seasonality=2)
>>> rmsse.score(y_true, y_pred)
0.5
Notes ¶
- RootMeanSquaredScaledError values are scale-independent, enabling comparison across different time series
- Values < 1 indicate better performance than naive seasonal forecast on training data
- Values > 1 indicate worse performance than naive seasonal baseline
- Requires training data with length > seasonality
- Per-column scaling factors are stored and applied independently
See Also ¶
RootMeanSquaredError: Root Mean Squared Error, non-scaled versionMeanAbsoluteError: Mean Absolute Error, non-scaled alternativeMeanSquaredError: Mean Squared Error, squared version
Source Code ¶
Source code in src/yohou/metrics/point.py
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 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 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 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 | |
Methods ¶
__sklearn_tags__()
¶
fit(y_train, *, forecaster=None, **params)
¶
Fit the scorer by computing per-column scaling factors.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
y_train
|
DataFrame
|
Training set target values with "time" column. |
required |
forecaster
|
BaseForecaster or None
|
If provided, metadata is extracted directly from the fitted
forecaster instead of being re-inferred from |
None
|
**params
|
dict
|
Metadata to route to nested estimators. |
{}
|
Returns ¶
| Type | Description |
|---|---|
self
|
|
Raises ¶
| Type | Description |
|---|---|
ValueError
|
If y_train is None or seasonality > len(y_train) - 1. |
Warns:
| Type | Description |
|---|---|
UserWarning
|
If any training column has zero variance for the given seasonality; a scale floor of 1e-10 is used instead. |
Source Code ¶
Source code in src/yohou/metrics/point.py
Tutorials¶
The following example notebooks use this component:
-
How to Use Point Forecast Metrics
Compare MAE, MAPE, MASE, RMSE, and other point metrics across multiple forecasters with componentwise and groupwise aggregation.