ContinuousRankedProbabilityScore¶
yohou.metrics.interval.ContinuousRankedProbabilityScore
¶
Bases: BaseIntervalScorer
Continuous Ranked Probability Score (CRPS) for prediction intervals.
Approximates CRPS by averaging pinball losses across multiple coverage rates. Each coverage rate α contributes two quantile levels, τ_lower = (1−α)/2 and τ_upper = (1+α)/2. The score averages the mean quantile loss per rate across all rates, approximating the integral of quantile loss over [0, 1].
The approximation improves as coverage rates become denser.
where \(L(\tau)\) is the pinball loss at quantile \(\tau\) and \(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:
Coverage rates are always collapsed ("coveragewise" is forced).
|
"all"
|
integration
|
('mean', 'trapezoidal')
|
Method for integrating pinball losses across coverage rates:
|
"mean"
|
coverage_rates
|
list of float or None
|
Coverage rate filter. Must contain at least 2 rates. Dict weights are not supported (use PinballLoss for custom weighting). |
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 CRPS (lower is better). |
Examples¶
>>> import polars as pl
>>> from datetime import datetime
>>> from yohou.metrics import ContinuousRankedProbabilityScore
>>> 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.5": [9.0, 19.0],
... "value_upper_0.5": [11.0, 21.0],
... "value_lower_0.9": [8.0, 18.0],
... "value_upper_0.9": [12.0, 22.0],
... })
>>> crps = ContinuousRankedProbabilityScore()
>>> _ = crps.fit(y_true)
>>> crps.score(y_true, y_pred)
0.17...
Notes¶
- Lower is better (0 = perfect forecast)
- Scale-dependent
- Requires at least 2 coverage rates
- For per-rate inspection, use PinballLoss instead
See Also¶
PinballLoss: Per-quantile loss with optional per-rate resultsIntervalScore: Combined coverage and sharpness metric
Source Code¶
Show/Hide source
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 | |
Methods¶
score(y_truth, y_pred, /, **params)
¶
Compute CRPS.
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
|
CRPS score. |
Raises¶
| Type | Description |
|---|---|
ValueError
|
If fewer than 2 coverage rates are provided. |