Core¶
uncertainty_flow.core
¶
Core classes for uncertainty_flow.
BaseUncertaintyModel
¶
Bases: ABC
Base class for all uncertainty quantification models.
All models must implement fit() and predict() methods. Calibration reports are provided via default implementation.
Source code in uncertainty_flow/core/base.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 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 | |
metadata
property
¶
Return persisted or derived metadata for the model.
Returns None for fresh unfitted models with no persisted metadata.
uncertainty_drivers_
property
¶
Return residual correlation analysis results.
Returns None if model has not been fitted.
Returns:
| Type | Description |
|---|---|
DataFrame | None
|
Polars DataFrame with feature-residual correlations, or None |
fit(data, target=None, **kwargs)
abstractmethod
¶
Fit the model to training data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
PolarsInput
|
Polars DataFrame or LazyFrame with features and target |
required |
target
|
TargetSpec | None
|
Target column name(s) - optional for some models |
None
|
**kwargs
|
Additional model-specific parameters |
{}
|
Returns:
| Type | Description |
|---|---|
BaseUncertaintyModel
|
self (for method chaining) |
Source code in uncertainty_flow/core/base.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
predict(data)
abstractmethod
¶
Generate probabilistic predictions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
PolarsInput
|
Polars DataFrame or LazyFrame with features |
required |
Returns:
| Type | Description |
|---|---|
DistributionPrediction
|
DistributionPrediction object with quantile predictions |
Source code in uncertainty_flow/core/base.py
45 46 47 48 49 50 51 52 53 54 55 56 | |
predict_batch(data, batch_size=1000)
¶
Generate probabilistic predictions in chunks.
Default implementation slices the data into batches and yields a
DistributionPrediction per batch. Models with native batch
/ GPU support (e.g. torch) should override this.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
PolarsInput
|
Polars DataFrame or LazyFrame with features |
required |
batch_size
|
int
|
Number of rows per batch (default 1000). |
1000
|
Yields:
| Type | Description |
|---|---|
DistributionPrediction
|
DistributionPrediction for each chunk. |
Source code in uncertainty_flow/core/base.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
calibration_report(data, target=None, quantile_levels=None)
¶
Generate calibration diagnostics.
Default implementation - can be overridden by subclasses.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
PolarsInput
|
Validation data |
required |
target
|
TargetSpec | None
|
Target column name(s) - optional for some models |
None
|
quantile_levels
|
list[float] | None
|
Quantile levels to evaluate (default: [0.8, 0.9, 0.95]) |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Polars DataFrame with calibration metrics |
Source code in uncertainty_flow/core/base.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
save(path, include_metadata=True)
¶
Save the model to a .uf archive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Output archive path. |
required |
include_metadata
|
bool
|
Whether to include extended metadata. |
True
|
Source code in uncertainty_flow/core/base.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
load(path, *, expected_archive_sha256=None)
classmethod
¶
Load a model from a .uf archive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Archive path produced by save(). |
required |
expected_archive_sha256
|
str | None
|
Optional SHA-256 hex digest expected for the archive. When provided, load() fails if the on-disk archive digest does not match. |
None
|
Returns:
| Type | Description |
|---|---|
BaseUncertaintyModel
|
Loaded model instance. |
Source code in uncertainty_flow/core/base.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
explain_interval_width(X, background=None, quantile_pairs=None)
¶
Compute SHAP values for quantile interval widths.
Identifies which features drive prediction interval width.
Thin wrapper around :func:uncertainty_shap.
Subclasses with native feature importance (e.g. quantile forests) may override this with a faster implementation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
PolarsInput
|
Feature DataFrame to explain. |
required |
background
|
PolarsInput | None
|
Background dataset for SHAP. Defaults to |
None
|
quantile_pairs
|
list[tuple[float, float]] | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Polars DataFrame with SHAP attributions per feature. |
Source code in uncertainty_flow/core/base.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
analyze_leverage(X, **kwargs)
¶
Analyze which features most influence prediction uncertainty.
Thin wrapper around :class:FeatureLeverageAnalyzer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
PolarsInput
|
Feature DataFrame for leverage analysis. |
required |
**kwargs
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Polars DataFrame with leverage scores per feature. |
Source code in uncertainty_flow/core/base.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
DistributionPrediction
¶
Holds predicted distributions for N samples.
Internal storage: NumPy arrays for efficiency. External interface: Polars DataFrames/Series.
Source code in uncertainty_flow/core/distribution.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 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 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 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 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 702 703 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 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 | |
quantile(q)
¶
Extract specific quantile levels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q
|
float | list[float]
|
Single quantile level or list of levels |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Polars DataFrame with columns like "q_0.05" or "price_q_0.05" for multivariate |
Source code in uncertainty_flow/core/distribution.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
interval(confidence=0.9)
¶
Return prediction interval.
For 0.9 confidence: uses 0.05 and 0.95 quantiles. Returns columns: lower, upper (or price_lower, price_upper for multivariate)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
confidence
|
float
|
Confidence level (e.g., 0.9 for 90% interval) |
0.9
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Polars DataFrame with lower/upper bounds |
Source code in uncertainty_flow/core/distribution.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
median()
¶
Return the 0.5 quantile as a point estimate.
Source code in uncertainty_flow/core/distribution.py
169 170 171 172 173 174 175 176 177 178 179 | |
crps(y_true)
¶
Compute the exact CRPS from quantile predictions.
Uses the quantile-score decomposition (Laio & Tamea 2007) — no Gaussian approximation. Requires at least 2 quantile levels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
Series | DataFrame | ndarray
|
True values. Polars Series (univariate), DataFrame (multivariate — one column per target), or numpy array. |
required |
Returns:
| Type | Description |
|---|---|
float | dict[str, float]
|
Float CRPS for univariate predictions, or |
float | dict[str, float]
|
for multivariate. |
Source code in uncertainty_flow/core/distribution.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 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 | |
pit_histogram(y_true, n_bins=10, chi2_test=False)
¶
Compute PIT histogram for calibration assessment.
If forecasts are perfectly calibrated, PIT values ~ Uniform(0, 1), so each bin should contain roughly n / n_bins observations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
Series | DataFrame | ndarray
|
True values. |
required |
n_bins
|
int
|
Number of histogram bins (default 10). |
10
|
chi2_test
|
bool
|
If True, include a chi-squared uniformity test p-value
as a |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame | dict[str, DataFrame]
|
DataFrame with columns: bin_center, count, expected. |
DataFrame | dict[str, DataFrame]
|
If |
DataFrame | dict[str, DataFrame]
|
For multivariate, returns {target: DataFrame}. |
Source code in uncertainty_flow/core/distribution.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
calibration_curve(y_true, n_bins=20)
¶
Compute reliability diagram data (calibration curve).
Bins PIT values and compares expected (nominal) coverage to observed (empirical) coverage at increasing probability thresholds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
Series | DataFrame | ndarray
|
True values. |
required |
n_bins
|
int
|
Number of bins (default 20). |
20
|
Returns:
| Type | Description |
|---|---|
DataFrame | dict[str, DataFrame]
|
DataFrame with columns: expected_coverage, observed_coverage. |
DataFrame | dict[str, DataFrame]
|
For multivariate, returns {target: DataFrame}. |
Source code in uncertainty_flow/core/distribution.py
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 | |
plot_pit(y_true, n_bins=10)
¶
Plot PIT histogram with uniform reference line. Requires matplotlib.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
Series | DataFrame | ndarray
|
True values. |
required |
n_bins
|
int
|
Number of histogram bins (default 10). |
10
|
Source code in uncertainty_flow/core/distribution.py
406 407 408 409 410 411 412 413 414 415 416 417 418 419 | |
sample(n, random_state=None)
¶
Draw n samples per input row via piecewise-linear inverse CDF.
For each row and each target, builds a CDF from the predicted quantile matrix (quantile values -> cumulative probability) and draws samples by inverting the CDF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of samples to draw per input row. |
required |
random_state
|
int | None
|
Optional random seed for reproducibility. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Polars DataFrame with (n * n_samples) rows and columns: |
DataFrame
|
|
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
InvalidDataError
|
If n is invalid or would exceed memory limits. |
Source code in uncertainty_flow/core/distribution.py
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 | |
plot(actuals=None, confidence_bands=None, title=None, targets='all', max_targets=6)
¶
Fan chart of quantile bands. Requires matplotlib.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
actuals
|
Series | DataFrame | None
|
Optional actual values for comparison. |
None
|
confidence_bands
|
list[float] | None
|
Confidence levels (default: [0.5, 0.8, 0.9, 0.95]). |
None
|
title
|
str | None
|
Optional plot title. |
None
|
targets
|
str | list[str]
|
Target(s) to plot. |
'all'
|
max_targets
|
int
|
Maximum subplot panels (default 6). |
6
|
Source code in uncertainty_flow/core/distribution.py
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 | |
posterior_samples()
¶
Return raw posterior parameter draws as a 2D matrix.
Source code in uncertainty_flow/core/distribution.py
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 | |
posterior_parameter_interval(confidence=0.9)
¶
Compute parameter credible intervals from posterior draws.
Source code in uncertainty_flow/core/distribution.py
671 672 673 674 675 676 677 678 679 | |
credible_interval(confidence=0.9)
¶
Compute predictive credible intervals for each prediction row.
Source code in uncertainty_flow/core/distribution.py
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 | |
rhat()
¶
Compute Gelman-Rubin R-hat convergence diagnostic from true chains.
Source code in uncertainty_flow/core/distribution.py
703 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 | |
posterior_summary()
¶
Return summary statistics of posterior samples.
Source code in uncertainty_flow/core/distribution.py
743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 | |
group_uncertainty()
¶
Return per-group uncertainty contribution (interval width).
Source code in uncertainty_flow/core/distribution.py
763 764 765 766 767 768 769 770 771 772 773 774 775 776 | |
group_intervals(confidence=0.9)
¶
Return per-group prediction intervals.
Source code in uncertainty_flow/core/distribution.py
778 779 780 781 782 783 784 785 | |
cross_group_correlation()
¶
Return cross-group correlation matrix based on group median predictions.
Source code in uncertainty_flow/core/distribution.py
787 788 789 790 791 792 793 794 795 796 797 798 799 800 | |
treatment_effect()
¶
Return CATE point estimates.
Source code in uncertainty_flow/core/distribution.py
804 805 806 807 808 809 810 811 | |
average_treatment_effect()
¶
Return ATE with confidence interval.
Source code in uncertainty_flow/core/distribution.py
813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 | |
heterogeneity_score()
¶
Return CATE variance as heterogeneity measure.
Source code in uncertainty_flow/core/distribution.py
829 830 831 832 833 834 835 836 | |
uncertainty_decomposition(confidence=0.9)
¶
Return a lightweight heuristic uncertainty decomposition. Aleatoric uncertainty (data noise): Irreducible uncertainty inherent in the data. Epistemic uncertainty (model uncertainty): Reducible uncertainty due to limited data/knowledge.
This method does not refit or evaluate an ensemble of models. It is a cheap
summary derived from this single DistributionPrediction object:
- Aleatoric: Average width of prediction intervals (data uncertainty)
- Epistemic: Variance of interval widths across samples (model uncertainty)
For model-based decomposition with bootstrap refits, use
uncertainty_flow.decomposition.EnsembleDecomposition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
confidence
|
float
|
Confidence level for interval width calculation (default: 0.9) |
0.9
|
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Dictionary with: - aleatoric: Irreducible uncertainty (average interval width) - epistemic: Heuristic uncertainty summary (variance of interval widths) - total: Combined uncertainty |
Examples¶
pred = model.predict(X_test) decomposition = pred.uncertainty_decomposition() print(f"Total: {decomposition['total']:.2f}") print(f" Aleatoric: {decomposition['aleatoric']:.2f}") print(f" Epistemic: {decomposition['epistemic']:.2f}")
Source code in uncertainty_flow/core/distribution.py
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 | |
summary(confidence=0.9)
¶
One-row-per-target overview of the prediction distribution.
Columns: target, median, mean_width_90, mean_width_50, aleatoric, epistemic, total_uncertainty.
mean_width_90 is the mean width at the confidence level.
mean_width_50 is the mean inter-quartile range (25th–75th percentile).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
confidence
|
float
|
Confidence level for the primary interval width (default 0.9). |
0.9
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Polars DataFrame with one row per target. |
Source code in uncertainty_flow/core/distribution.py
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 940 941 942 943 944 945 946 947 948 949 950 951 952 | |
fit_distribution(family='auto', row_index=None)
¶
Fit a parametric distribution to the quantile predictions.
For univariate predictions, fits a single distribution. For multivariate, fits one distribution per target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
family
|
str
|
One of |
'auto'
|
row_index
|
int | None
|
If given, fit only for that row. Otherwise fit for the mean quantile vector across all rows. |
None
|
Returns:
| Type | Description |
|---|---|
ParametricDistribution | list[ParametricDistribution]
|
A single |
ParametricDistribution | list[ParametricDistribution]
|
of |
ParametricDistribution | list[ParametricDistribution]
|
When |
ParametricDistribution | list[ParametricDistribution]
|
for univariate or a list for multivariate. |
Source code in uncertainty_flow/core/distribution.py
954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 | |
log_score(y_true, family='auto')
¶
Compute the mean negative log-likelihood (log-score).
Fits a parametric distribution from the predicted quantiles, then evaluates the log-density at the true values. Higher is better (less negative).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
Series | DataFrame | ndarray
|
True values. |
required |
family
|
str
|
Distribution family for fitting, or |
'auto'
|
Returns:
| Type | Description |
|---|---|
float | dict[str, float]
|
Mean log-score (float) for univariate, or |
float | dict[str, float]
|
for multivariate. |
Source code in uncertainty_flow/core/distribution.py
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 | |
energy_score(y_true, n_samples=1000, random_state=None)
¶
Compute the energy score for multivariate predictions.
A proper scoring rule that generalises CRPS to the multivariate case. Requires at least 2 targets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
Series | DataFrame | ndarray
|
True values (array with columns matching targets). |
required |
n_samples
|
int
|
Monte Carlo samples per observation. |
1000
|
random_state
|
int | None
|
Random seed. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
Mean energy score (float). |
Source code in uncertainty_flow/core/distribution.py
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 | |
variogram_score(y_true, n_samples=1000, p=0.5, random_state=None)
¶
Compute the variogram score for multivariate predictions.
A proper scoring rule sensitive to the correlation structure. Requires at least 2 targets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
Series | DataFrame | ndarray
|
True values (array with columns matching targets). |
required |
n_samples
|
int
|
Monte Carlo samples per observation. |
1000
|
p
|
float
|
Power parameter (default 0.5). |
0.5
|
random_state
|
int | None
|
Random seed. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
Mean variogram score (float). |
Source code in uncertainty_flow/core/distribution.py
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 | |
ParametricDistribution
¶
Parametric distribution fitted from quantile predictions.
Supported families: "normal", "student_t", "lognormal",
"gamma", "auto" (selects best by KS distance).
Source code in uncertainty_flow/core/parametric.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
PredictionSet
¶
Prediction set for conformal classification.
For each sample, stores the set of classes included at the calibrated
coverage level. Analogous to DistributionPrediction for regression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
class_sets
|
list[list[str]]
|
List of lists — each inner list contains the class labels included in that sample's prediction set. |
required |
class_names
|
list[str]
|
Ordered list of all class names. |
required |
probabilities
|
ndarray
|
(n_samples, n_classes) matrix of softmax probabilities. |
required |
coverage_target
|
float
|
The target marginal coverage level. |
required |
threshold
|
float
|
The APS threshold used to construct the sets. |
required |
Source code in uncertainty_flow/core/prediction_set.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
coverage
property
¶
Return the theoretical target coverage level.
size
property
¶
Return the average set size across all samples.
set(sample_index=None)
¶
Return the prediction set for one or all samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample_index
|
int | None
|
Index of a single sample, or |
None
|
Returns:
| Type | Description |
|---|---|
list[str] | list[list[str]]
|
Single list of class labels, or list of lists for all samples. |
Source code in uncertainty_flow/core/prediction_set.py
44 45 46 47 48 49 50 51 52 53 54 55 | |
size_by_sample()
¶
Return the set size for each sample.
Source code in uncertainty_flow/core/prediction_set.py
67 68 69 | |
probabilities()
¶
Return the softmax probability matrix as a Polars DataFrame.
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with columns |
Source code in uncertainty_flow/core/prediction_set.py
71 72 73 74 75 76 77 78 | |
summary()
¶
Return a one-row summary of the prediction set.
Columns: coverage_target, avg_set_size, n_samples, n_classes.
Source code in uncertainty_flow/core/prediction_set.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
get_config()
¶
Get the global configuration instance, creating a default on first call.
Source code in uncertainty_flow/core/config.py
84 85 86 87 88 89 | |
reset_config()
¶
Reset configuration to defaults.
Source code in uncertainty_flow/core/config.py
98 99 100 101 | |
set_config(config)
¶
Set a custom global configuration.
Source code in uncertainty_flow/core/config.py
92 93 94 95 | |
fit_parametric(quantile_values, quantile_levels, family='auto')
¶
Fit a parametric distribution from quantile knots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quantile_values
|
ndarray
|
1-D array of predicted quantile values. |
required |
quantile_levels
|
ndarray
|
1-D array of quantile levels in (0, 1). |
required |
family
|
str
|
Distribution family or |
'auto'
|
Returns:
| Type | Description |
|---|---|
ParametricDistribution
|
Fitted |
Source code in uncertainty_flow/core/parametric.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | |