Plotting¶
online_cp.plotting.plot_coverage(metric: Metric, *, nominal: float | None = None, ax: Axes | None = None, **kwargs: Any) -> Axes
¶
Plot the running coverage (1 - error rate) over time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric
|
Metric
|
A metric object with a |
required |
nominal
|
float
|
Nominal coverage level (e.g. 0.9). Draws a horizontal reference line. |
None
|
ax
|
Axes
|
Axes to plot on. If None, creates a new figure. |
None
|
**kwargs
|
Any
|
Passed to |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
ax |
Axes
|
|
Source code in src/online_cp/plotting.py
online_cp.plotting.plot_detector(wrapper: VilleWrapper | CUSUMWrapper | ShiryaevRobertsWrapper, *, threshold: float | None = None, log_scale: bool = True, change_point: int | None = None, ax: Axes | None = None, **kwargs: Any) -> Axes
¶
Plot a detection wrapper's statistic trajectory with alarm markers.
Accepts a VilleWrapper, CUSUMWrapper, or ShiryaevRobertsWrapper and renders the appropriate diagnostic plot including threshold lines and alarm time markers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wrapper
|
VilleWrapper, CUSUMWrapper, or ShiryaevRobertsWrapper
|
A detection wrapper that has been updated with p-values. |
required |
threshold
|
float or None
|
Alarm threshold to draw. For VilleWrapper, defaults to |
None
|
log_scale
|
bool
|
If True (default), plot in log₁₀ scale. If False, plot on natural scale. |
True
|
change_point
|
int or None
|
If provided, draw a vertical dashed line at this step (true change-point). |
None
|
ax
|
Axes
|
Axes to plot on. If None, creates a new figure. |
None
|
**kwargs
|
Any
|
Passed to the main trajectory |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
ax |
Axes
|
|
Source code in src/online_cp/plotting.py
online_cp.plotting.plot_martingale(martingale: ConformalTestMartingale, *, log_scale: bool = True, threshold: float | None = 100, ax: Axes | None = None, **kwargs: Any) -> Axes
¶
Plot a martingale trajectory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
martingale
|
ConformalTestMartingale
|
A martingale object with |
required |
log_scale
|
bool
|
If True (default), plot log10(M_n). If False, plot M_n. |
True
|
threshold
|
float or None
|
Draw a horizontal line at this rejection threshold. None = no line. |
100
|
ax
|
Axes
|
Axes to plot on. |
None
|
**kwargs
|
Any
|
Passed to |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
ax |
Axes
|
|
Source code in src/online_cp/plotting.py
online_cp.plotting.plot_intervals(y_true: NDArray[np.floating[Any]] | Sequence[float], intervals: Sequence[Any], *, ax: Axes | None = None, point_kwargs: dict[str, Any] | None = None, interval_kwargs: dict[str, Any] | None = None) -> Axes
¶
Plot prediction intervals with true values overlaid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
array - like
|
True response values. |
required |
intervals
|
list of tuples or objects with .lower/.upper attributes
|
Prediction intervals. Each element is either a (lower, upper) tuple
or an object with |
required |
ax
|
Axes
|
Axes to plot on. |
None
|
point_kwargs
|
dict
|
Keyword arguments for the true-value scatter plot. |
None
|
interval_kwargs
|
dict
|
Keyword arguments for the interval vertical lines. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
ax |
Axes
|
|
Source code in src/online_cp/plotting.py
online_cp.plotting.plot_set_sizes(metric: Metric, *, ax: Axes | None = None, **kwargs: Any) -> Axes
¶
Plot running average set size (or interval width) over time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric
|
Metric
|
A metric with a |
required |
ax
|
Axes
|
Axes to plot on. |
None
|
**kwargs
|
Any
|
Passed to |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
ax |
Axes
|
|
Source code in src/online_cp/plotting.py
Calibration Diagnostics¶
online_cp.plotting.plot_reliability_diagram(predicted: NDArray | Any, observed: NDArray | None = None, *, n_bins: int = 10, strategy: str = 'uniform', ax: Axes | None = None, **kwargs: Any) -> Axes
¶
Plot a reliability diagram (calibration curve).
Bins predicted probabilities and plots mean predicted vs observed frequency, with a diagonal reference line for perfect calibration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predicted
|
ndarray or CalibrationError
|
Array of predicted probabilities in [0, 1], or a
|
required |
observed
|
ndarray or None
|
Binary array of outcomes (1 = positive, 0 = negative).
Required if |
None
|
n_bins
|
int
|
Number of bins. |
10
|
strategy
|
str
|
|
"uniform"
|
ax
|
Axes
|
Axes to plot on. |
None
|
**kwargs
|
Any
|
Passed to the main |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
ax |
Axes
|
|
Source code in src/online_cp/plotting.py
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 | |
online_cp.plotting.plot_reliability_diagram_venn(predictions: Sequence[Any], labels: NDArray | Sequence, *, n_bins: int = 10, which: str = 'both', target_label: int | None = None, ax: Axes | None = None, **kwargs: Any) -> Axes
¶
Reliability diagram for Venn multiprobability predictions.
Demonstrates the Venn calibration guarantee by plotting:
- point: reliability of the aggregated point estimate
- hypothesis: reliability of the correct-hypothesis probability
:math:
P^y(y)(theoretically calibrated) - both: overlays both curves
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
sequence of VennPrediction
|
Multiprobability predictions. |
required |
labels
|
array - like
|
True labels corresponding to each prediction. |
required |
n_bins
|
int
|
Number of bins. |
10
|
which
|
str
|
|
"both"
|
target_label
|
int or None
|
For binary predictions, which label to plot P(y=target_label). Defaults to label_space[1] (the positive class). |
None
|
ax
|
Axes
|
Axes to plot on. |
None
|
**kwargs
|
Any
|
Passed to |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
ax |
Axes
|
|
Source code in src/online_cp/plotting.py
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 | |
online_cp.plotting.plot_sharpness(predictions: Sequence[Any], *, n_bins: int = 20, ax: Axes | None = None, **kwargs: Any) -> Axes
¶
Histogram of Venn multiprobability widths (sharpness).
For binary predictions, plots the distribution of :math:|p_1 - p_0|.
For multiclass, plots the mean per-label width (max − min across
hypotheses).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
sequence of VennPrediction
|
Multiprobability predictions. |
required |
n_bins
|
int
|
Number of histogram bins. |
20
|
ax
|
Axes
|
Axes to plot on. |
None
|
**kwargs
|
Any
|
Passed to |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
ax |
Axes
|
|
Source code in src/online_cp/plotting.py
online_cp.plotting.plot_pit_histogram(pit_values: NDArray | Sequence[float], *, n_bins: int = 10, ax: Axes | None = None, **kwargs: Any) -> Axes
¶
PIT histogram for conformal predictive distributions.
Plots a histogram of Probability Integral Transform values
:math:F(y_{\text{true}}) and compares to the Uniform[0,1]
reference. Under exchangeability, PIT values should be uniform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pit_values
|
array - like
|
PIT values, typically computed as |
required |
n_bins
|
int
|
Number of histogram bins. |
10
|
ax
|
Axes
|
Axes to plot on. |
None
|
**kwargs
|
Any
|
Passed to |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
ax |
Axes
|
|
Source code in src/online_cp/plotting.py
online_cp.plotting.plot_calibration_conditional(metric_dict: dict[str, Any], *, n_bins: int = 10, strategy: str = 'uniform', ax: Axes | None = None, **kwargs: Any) -> Axes
¶
Overlay reliability diagrams for multiple groups (Mondrian lens).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric_dict
|
dict[str, CalibrationError]
|
Mapping from group name to |
required |
n_bins
|
int
|
Number of bins per group. |
10
|
strategy
|
str
|
Binning strategy: |
"uniform"
|
ax
|
Axes
|
Axes to plot on. |
None
|
**kwargs
|
Any
|
Passed to each |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
ax |
Axes
|
|