CalibrationError¶
yohou.metrics.interval.CalibrationError
¶
Bases: BaseIntervalScorer
Calibration Error for prediction intervals.
Measures the discrepancy between nominal coverage rate and empirical coverage across different rates. Indicates if intervals are well-calibrated.
The calibration error is:
where K is the number of coverage rates.
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
aggregation_method
|
list of str or str
|
Dimensions to collapse when aggregating scores. Orthogonal modes:
|
"all"
|
coverage_rates
|
list of float, dict of float to float, or None
|
Coverage rate filter (list) or filter with weights (dict). |
None
|
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
|
True for calibration error (lower is better). |
Examples¶
>>> import polars as pl
>>> from datetime import datetime
>>> from yohou.metrics import CalibrationError
>>> y_true = pl.DataFrame({"time": [datetime(2020, 1, 1), datetime(2020, 1, 2)], "value": [10.0, 20.0]})
>>> y_pred = pl.DataFrame({
... "vintage_time": [datetime(2019, 12, 31)] * 2,
... "time": [datetime(2020, 1, 1), datetime(2020, 1, 2)],
... "value_lower_0.9": [8.0, 18.0],
... "value_upper_0.9": [12.0, 22.0],
... "value_lower_0.95": [7.0, 17.0],
... "value_upper_0.95": [13.0, 23.0],
... })
>>> error = CalibrationError()
>>> _ = error.fit(y_true)
>>> error.score(y_true, y_pred)
0.0...
Notes¶
- Lower is better (0 = perfect calibration)
- Aggregates coverage errors across all rates
- Scale-independent (always between 0 and 1)
- Requires at least 2 coverage rates for meaningful metric
- Missing values are excluded from computation
See Also¶
EmpiricalCoverage: Per-rate coverage metricIntervalScore: Combined coverage and sharpness metric
Source Code¶
Show/Hide source
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 | |
Methods¶
score(y_truth, y_pred, /, **params)
¶
Compute calibration error.
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
y_truth
|
DataFrame
|
True values with "time" column. |
required |
y_pred
|
DataFrame
|
Predicted intervals with "{col}lower}", "{colupper" columns. |
required |
**params
|
dict
|
Metadata to route to nested estimators. |
{}
|
Returns¶
| Type | Description |
|---|---|
float or DataFrame
|
Calibration error score. |
Raises¶
| Type | Description |
|---|---|
ValueError
|
If fewer than 2 coverage rates are provided. |
Source Code¶
Show/Hide source
Tutorials¶
The following example notebooks use this component:
-
How to Evaluate Interval Forecasts
Evaluation-Search
Evaluate prediction intervals with EmpiricalCoverage, IntervalScore, MeanIntervalWidth, PinballLoss, and CalibrationError across coverage levels.