Metrics
This page documents the metrics module.
ordboost.metrics
Evaluation metrics for discrete ordinal and continuous probabilistic forecasts.
baseline_distribution(y_train, n_samples, boundary_epsilon=0.0001)
Construct a no-covariate baseline distribution.
Builds the unconditional empirical CDF of y_train and broadcasts it
identically across n_samples rows, representing the best achievable
forecast in the complete absence of covariate information -- the
standard reference forecast against which skill scores are computed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_train
|
ArrayLike of shape (n_train_samples,)
|
Training targets defining the unconditional empirical distribution.
Should be the full, unfiltered training set, even when scoring a
filtered evaluation subset, so the baseline continues to represent
"no covariate information" rather than "no information restricted
to a subgroup" (see |
required |
n_samples
|
int
|
Number of rows to broadcast the baseline CDF across, e.g. the number of samples in the evaluation set this baseline will be scored against. |
required |
boundary_epsilon
|
float
|
Offset used to place a grid point strictly below the observed
minimum of |
1e-4
|
Returns:
| Type | Description |
|---|---|
ContinuousPredictiveDistribution
|
A distribution with |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in ordboost/metrics.py
crps_score(y_true, y_dist, sample_weight=None)
Compute the Continuous Ranked Probability Score (CRPS).
For discrete distributions, evaluates the exact squared cumulative
probability error across threshold classes (a finite sum, not an
approximation). For continuous predictive distributions, evaluates
the exact integrated squared distance between the predicted CDF
F(y) and the empirical step function I(y_true <= y), via
scores.probability.crps_cdf. This computes the exact integral for
a piecewise-linear CDF -- including correctly splitting the grid
segment containing y_true -- rather than approximating it via
trapezoidal integration over grid points alone, which systematically
under- or over-estimates depending on where y_true falls within a
segment (worse for wider bins).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
ArrayLike of shape (n_samples,)
|
True physical target values. |
required |
y_dist
|
PredictiveDistribution
|
Predicted probability distribution object (discrete or continuous). |
required |
sample_weight
|
ArrayLike of shape (n_samples,)
|
Sample weights for weighted mean computation. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
The average CRPS across all samples (lower is better). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in ordboost/metrics.py
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 | |
crps_skill_score(y_true, dist_model, dist_baseline, sample_weight=None)
Compute the CRPS skill score relative to a reference forecast.
Defined as CRPSS = 1 - CRPS(model) / CRPS(baseline). A value of 0
indicates no improvement over the baseline, 1 indicates a perfect
forecast, and negative values indicate performance worse than the
baseline. dist_baseline is typically constructed via
baseline_distribution, but may be any reference forecast.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
ArrayLike of shape (n_samples,)
|
True physical target values. |
required |
dist_model
|
ContinuousPredictiveDistribution
|
The model's predicted distribution. |
required |
dist_baseline
|
ContinuousPredictiveDistribution
|
The reference forecast distribution to compare against. |
required |
sample_weight
|
ArrayLike of shape (n_samples,)
|
Sample weights, applied identically to both CRPS computations. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
The CRPS skill score. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in ordboost/metrics.py
interval_coverage_rate(y_true, dist, alpha=0.1, sample_weight=None, tolerance=0.0)
Compute empirical coverage rate for a central prediction interval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
ArrayLike of shape (n_samples,)
|
True continuous target values. |
required |
dist
|
ContinuousPredictiveDistribution
|
Predicted continuous distributions. |
required |
alpha
|
float
|
Tail significance level (e.g., alpha=0.10 specifies a 90% interval). |
0.10
|
sample_weight
|
ArrayLike of shape (n_samples,)
|
Sample weights for weighted coverage computation. |
None
|
tolerance
|
float
|
Slack applied to both bounds before the containment check. Use the
mapper's |
0.0
|
Returns:
| Type | Description |
|---|---|
float
|
Proportion of true observations lying within predicted interval bounds. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If alpha not within (0.0, 1.0); or sample_weights do not have the same shape as y_arr. |
Source code in ordboost/metrics.py
marginal_calibration_curve(y_true, dist, mapper)
Compute the difference between the empirical CDF and the average CDF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
ArrayLike of shape (n_samples,)
|
True continuous target values. |
required |
dist
|
ContinuousPredictiveDistribution
|
Predicted continuous distributions. |
required |
mapper
|
BaseBinMapper
|
The (fitted or unfitted) mapper instance whose |
required |
Returns:
| Name | Type | Description |
|---|---|---|
grid_y |
np.ndarray of shape (n_points,)
|
Grid points at which CDF were evaluated. |
calibration |
np.ndarray of shape (n_points,)
|
Marginal calibration. |
Source code in ordboost/metrics.py
pinball_loss(y_true, y_pred_q, q, sample_weight=None)
Compute the pinball (quantile) loss for a specific quantile level q.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
ArrayLike of shape (n_samples,)
|
True physical target labels. |
required |
y_pred_q
|
ArrayLike of shape (n_samples,)
|
Predicted target values at quantile level |
required |
q
|
float
|
Target quantile level in the range (0.0, 1.0). |
required |
sample_weight
|
ArrayLike of shape (n_samples,)
|
Sample weights for weighted mean computation. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
The average pinball loss across samples. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in ordboost/metrics.py
pinball_loss_skill_score(y_true, dist_model, dist_baseline, q, sample_weight=None)
Compute the pinball loss skill score at quantile level q.
Defined as PLSS = 1 - pinball_loss(model) / pinball_loss(baseline),
both evaluated at the same quantile level q and against the same
y_true. Interpretation mirrors crps_skill_score: 0 indicates no
improvement over the baseline, 1 indicates a perfect forecast at that
quantile, negative values indicate worse-than-baseline performance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
ArrayLike of shape (n_samples,)
|
True physical target values. |
required |
dist_model
|
ContinuousPredictiveDistribution
|
The model's predicted distribution. |
required |
dist_baseline
|
ContinuousPredictiveDistribution
|
The reference forecast distribution to compare against. |
required |
q
|
float
|
Quantile level in (0.0, 1.0) at which to evaluate both forecasts. |
required |
sample_weight
|
ArrayLike of shape (n_samples,)
|
Sample weights, applied identically to both pinball loss computations. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
The pinball loss skill score at quantile |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in ordboost/metrics.py
pit_diagnostics(y_true, dist, mapper, precision=2, resolution=1.0)
Construct exact PIT diagnostics using only per-sample scalars (O(n_samples)), not the full CDF grid (O(n_samples * n_grid_points)).
Each observation y is treated as the half-open bin [y, y + resolution),
so its PIT value is uniform on [F(y), F(y + resolution)], where the
CDF values are evaluated directly via dist.cdf(), rather than handing
the entire grid_cdf array to Pit's threshold-dimension mode. Atoms at
the floor and ceiling are handled separately, since they are point masses
and not bins. The data from the distribution is rounded to the given
precision, to avoid memory issues for large datasets, unless precision is
None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
ArrayLike of shape (n_samples,)
|
True target values, quantized to multiples of |
required |
dist
|
ContinuousPredictiveDistribution
|
Predicted continuous distributions, with |
required |
mapper
|
BaseBinMapper
|
The (fitted or unfitted) mapper instance whose |
required |
precision
|
int or None
|
Number of decimal places to round the PIT bounds to before
constructing |
2
|
resolution
|
float
|
Width of the interval represented by each observed value, i.e. the quantization step of the target (1.0 for integer-valued outcomes). |
1.0
|
Returns:
| Type | Description |
|---|---|
PitFcstAtObs
|
A fitted |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
TypeError
|
If |
Source code in ordboost/metrics.py
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 | |
pit_ks_test(pit)
Compute a Kolmogorov-Smirnov test of PIT uniformity.
Convenience wrapper around scipy.stats.kstest, using pit's
duplicate-free plotting points. For discontinuous-CDF calibration
assessment the alpha score is prefered and computed directly
from the Pit object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pit
|
PitFcstAtObs | Pit
|
A fitted |
required |
Returns:
| Name | Type | Description |
|---|---|---|
statistic |
float
|
The KS test statistic. |
p_value |
float
|
The associated p-value. |
Source code in ordboost/metrics.py
sharpness(dist, alpha=0.1)
Compute mean interval width at significance level alpha.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dist
|
ContinuousPredictiveDistribution
|
Predicted continuous distributions. |
required |
alpha
|
float
|
Tail significance level in range (0.0, 1.0). |
0.10
|
Returns:
| Type | Description |
|---|---|
float
|
Mean interval width. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If alpha not within (0.0, 1.0) |
Source code in ordboost/metrics.py
winkler_score(y_true, dist, alpha=0.1, sample_weight=None)
Compute mean Winkler score for prediction intervals at significance level alpha.
Penalizes interval width and asymmetrically penalizes targets that fall outside the predicted lower and upper bounds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
ArrayLike of shape (n_samples,)
|
True continuous target values. |
required |
dist
|
ContinuousPredictiveDistribution
|
Predicted continuous distributions. |
required |
alpha
|
float
|
Tail significance level in range (0.0, 1.0). |
0.10
|
sample_weight
|
ArrayLike of shape (n_samples,)
|
Sample weights for weighted mean computation. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
Mean Winkler score across samples (lower is better). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If alpha not within (0.0, 1.0) |