Metrics
uqdd.metrics ¶
Metrics subpackage for UQDD
The uqdd.metrics subpackage provides tools to compute, analyze, and
visualize performance and uncertainty metrics for UQDD models. It includes
plotting and analysis helpers, statistical testing routines, and reassessment
utilities to benchmark and compare models rigorously.
Modules:
| Name | Description |
|---|---|
- ``constants``: Canonical metric names, grouping orders, hatches, and helper |
structures to standardize plots and reports. |
- ``analysis``: Functions for aggregating results, loading predictions, |
computing rejection curves, and producing comparison plots and calibration visualizations. |
- ``stats``: Statistical metrics and tests |
bootstrapping, Wilcoxon, Holm–Bonferroni, Friedman–Nemenyi, Cliff's delta), along with boxplots, curve plots, and significance analysis/reporting. |
- ``reassessment``: Utilities to reassess runs and models |
evidential models), export predictions, and post-process metrics from CSV. |
Public API
Commonly used names are re-exported for convenient access via
uqdd.metrics.<name>. They are grouped by module below for discoverability.
-
Constants
group_cols,numeric_cols,string_cols,order_by,group_order,group_order_no_time,hatches_dict,hatches_dict_no_time,accmetrics,accmetrics2,uctmetrics,uctmetrics2 -
Analysis
aggregate_results_csv,save_plot,handle_inf_values,plot_pairplot,plot_line_metrics,plot_histogram_metrics,plot_pairwise_scatter_metrics,plot_metrics,find_highly_correlated_metrics,plot_comparison_metrics,load_and_aggregate_calibration_data,plot_calibration_data,move_model_folders,load_predictions,calculate_rmse_rejection_curve,calculate_rejection_curve,get_handles_labels,plot_rmse_rejection_curves,plot_auc_comparison,save_stats_df,load_stats_df -
Statistics
calc_regression_metrics,bootstrap_ci,rm_tukey_hsd,make_boxplots,make_boxplots_parametric,make_boxplots_nonparametric,make_sign_plots_nonparametric,make_critical_difference_diagrams,make_normality_diagnostic,mcs_plot,make_mcs_plot_grid,make_scatterplot,ci_plot,make_ci_plot_grid,recall_at_precision,calc_classification_metrics,make_curve_plots,harmonize_columns,cliffs_delta,wilcoxon_pairwise_test,holm_bonferroni_correction,pairwise_model_comparison,friedman_nemenyi_test,calculate_critical_difference,bootstrap_auc_difference,plot_critical_difference_diagram,analyze_significance,comprehensive_statistical_analysis,generate_statistical_report -
Reassessment
nll_evidentials,convert_to_list,preprocess_runs,get_model_class,get_predict_fn,get_preds,pkl_preds_export,csv_nll_post_processing,reassess_metrics
Usage Notes
- Reproducibility: Prefer functions that accept random seeds and write
diagnositics under
uqdd/logs; capture versions and configurations for statistical comparisons. - Data paths: Use the global paths from
uqdd.__init__to keep file/plot outputs consistent. - Plot styles: Use constants from
metrics.constantsto standardize the look and ordering across figures.
uqdd.metrics.group_cols
module-attribute
¶
group_cols = ['Model type', 'Task', 'Activity', 'Split', 'desc_prot', 'desc_chem', 'dropout']
uqdd.metrics.numeric_cols
module-attribute
¶
numeric_cols = ['RMSE', 'R2', 'MAE', 'MDAE', 'MARPD', 'PCC', 'RMS Calibration', 'MA Calibration', 'Miscalibration Area', 'Sharpness', 'NLL', 'CRPS', 'Check', 'Interval', 'rho_rank', 'rho_rank_sim', 'rho_rank_sim_std', 'uq_mis_cal', 'uq_NLL', 'uq_NLL_sim', 'uq_NLL_sim_std', 'Z_var', 'Z_var_CI_low', 'Z_var_CI_high', 'Z_mean', 'Z_mean_CI_low', 'Z_mean_CI_high', 'rmv_rmse_slope', 'rmv_rmse_r_sq', 'rmv_rmse_intercept', 'aleatoric_uct_mean', 'epistemic_uct_mean', 'total_uct_mean']
uqdd.metrics.string_cols
module-attribute
¶
string_cols = ['wandb project', 'wandb run', 'model name']
uqdd.metrics.group_order
module-attribute
¶
group_order = ['stratified_pnn', 'stratified_ensemble', 'stratified_mcdropout', 'stratified_evidential', 'stratified_eoe', 'stratified_emc', 'scaffold_cluster_pnn', 'scaffold_cluster_ensemble', 'scaffold_cluster_mcdropout', 'scaffold_cluster_evidential', 'scaffold_cluster_eoe', 'scaffold_cluster_emc', 'time_pnn', 'time_ensemble', 'time_mcdropout', 'time_evidential', 'time_eoe', 'time_emc']
uqdd.metrics.group_order_no_time
module-attribute
¶
group_order_no_time = ['stratified_pnn', 'stratified_ensemble', 'stratified_mcdropout', 'stratified_evidential', 'stratified_eoe', 'stratified_emc', 'scaffold_cluster_pnn', 'scaffold_cluster_ensemble', 'scaffold_cluster_mcdropout', 'scaffold_cluster_evidential', 'scaffold_cluster_eoe', 'scaffold_cluster_emc']
uqdd.metrics.hatches_dict
module-attribute
¶
hatches_dict = {'stratified': '\\\\', 'scaffold_cluster': '', 'time': '...'}
uqdd.metrics.hatches_dict_no_time
module-attribute
¶
hatches_dict_no_time = {'stratified': '\\\\', 'scaffold_cluster': ''}
uqdd.metrics.accmetrics
module-attribute
¶
accmetrics = ['RMSE', 'R2', 'MAE', 'MDAE', 'MARPD', 'PCC']
uqdd.metrics.uctmetrics
module-attribute
¶
uctmetrics = ['RMS Calibration', 'MA Calibration', 'Miscalibration Area', 'Sharpness', 'CRPS', 'Check', 'NLL', 'Interval']
uqdd.metrics.uctmetrics2
module-attribute
¶
uctmetrics2 = ['Miscalibration Area', 'Sharpness', 'CRPS', 'NLL', 'Interval']
uqdd.metrics.__all__
module-attribute
¶
__all__ = ['group_cols', 'numeric_cols', 'string_cols', 'order_by', 'group_order', 'group_order_no_time', 'hatches_dict', 'hatches_dict_no_time', 'accmetrics', 'accmetrics2', 'uctmetrics', 'uctmetrics2', 'aggregate_results_csv', 'save_plot', 'handle_inf_values', 'plot_pairplot', 'plot_line_metrics', 'plot_histogram_metrics', 'plot_pairwise_scatter_metrics', 'plot_metrics', 'find_highly_correlated_metrics', 'plot_comparison_metrics', 'load_and_aggregate_calibration_data', 'plot_calibration_data', 'move_model_folders', 'load_predictions', 'calculate_rmse_rejection_curve', 'calculate_rejection_curve', 'get_handles_labels', 'plot_rmse_rejection_curves', 'plot_auc_comparison', 'save_stats_df', 'load_stats_df', 'calc_regression_metrics', 'bootstrap_ci', 'rm_tukey_hsd', 'make_boxplots', 'make_boxplots_parametric', 'make_boxplots_nonparametric', 'make_sign_plots_nonparametric', 'make_critical_difference_diagrams', 'make_normality_diagnostic', 'mcs_plot', 'make_mcs_plot_grid', 'make_scatterplot', 'ci_plot', 'make_ci_plot_grid', 'recall_at_precision', 'calc_classification_metrics', 'make_curve_plots', 'harmonize_columns', 'cliffs_delta', 'wilcoxon_pairwise_test', 'holm_bonferroni_correction', 'pairwise_model_comparison', 'friedman_nemenyi_test', 'calculate_critical_difference', 'bootstrap_auc_difference', 'plot_critical_difference_diagram', 'analyze_significance', 'comprehensive_statistical_analysis', 'generate_statistical_report', 'nll_evidentials', 'convert_to_list', 'preprocess_runs', 'get_model_class', 'get_predict_fn', 'get_preds', 'pkl_preds_export', 'csv_nll_post_processing', 'reassess_metrics']
uqdd.metrics.aggregate_results_csv ¶
aggregate_results_csv(df: DataFrame, group_cols: List[str], numeric_cols: List[str], string_cols: List[str], order_by: Optional[Union[str, List[str]]] = None, output_file_path: Optional[str] = None) -> pd.DataFrame
Aggregate metrics by groups and export a compact CSV summary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input results DataFrame. |
required |
group_cols
|
list of str
|
Column names to group by. |
required |
numeric_cols
|
list of str
|
Numeric metric columns to aggregate with mean and std. |
required |
string_cols
|
list of str
|
String columns to aggregate as lists. |
required |
order_by
|
str or list of str or None
|
Column(s) to sort the final aggregated DataFrame by. Default is None. |
None
|
output_file_path
|
str or None
|
Path to write the aggregated CSV. If None, no file is written. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Aggregated DataFrame with combined mean(std) strings plus string/list aggregates. |
Notes
- A helper column
project_modelis constructed and included in the aggregates. - When
output_file_pathis provided, the function ensures the directory exists.
Source code in uqdd/metrics/analysis.py
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 | |
uqdd.metrics.save_plot ¶
save_plot(fig: Figure, save_dir: Optional[str], plot_name: str, tighten: bool = True, show_legend: bool = False) -> None
Save a matplotlib figure to PNG, SVG, and PDF with optional tight layout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig
|
Figure
|
Figure to save. |
required |
save_dir
|
str or None
|
Directory to save the figure files. If None, no files are written. |
required |
plot_name
|
str
|
Base filename (without extension). |
required |
tighten
|
bool
|
If True, apply tight_layout and bbox_inches="tight". Default is True. |
True
|
show_legend
|
bool
|
If False, remove legend before saving. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/analysis.py
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 | |
uqdd.metrics.handle_inf_values ¶
handle_inf_values(df: DataFrame) -> pd.DataFrame
Replace +/- infinity values in a DataFrame with NaN.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with infinite values replaced by NaN. |
Source code in uqdd/metrics/analysis.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
uqdd.metrics.plot_pairplot ¶
plot_pairplot(df: DataFrame, title: str, metrics: List[str], save_dir: Optional[str] = None, cmap: str = 'viridis', group_order: Optional[List[str]] = group_order, show_legend: bool = False) -> None
Plot a seaborn pairplot for a set of metrics colored by Group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame containing the metrics and a 'Group' column. |
required |
title
|
str
|
Plot title. |
required |
metrics
|
list of str
|
Metric column names to include in the pairplot. |
required |
save_dir
|
str or None
|
Directory to save plot images. Default is None. |
None
|
cmap
|
str
|
Seaborn/matplotlib palette name. Default is "viridis". |
'viridis'
|
group_order
|
list of str or None
|
Order of class labels in the legend. Default is from constants. |
group_order
|
show_legend
|
bool
|
If True, keep the legend; otherwise it will be removed before saving. |
False
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/analysis.py
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 | |
uqdd.metrics.plot_line_metrics ¶
plot_line_metrics(df: DataFrame, title: str, metrics: List[str], save_dir: Optional[str] = None, group_order: Optional[List[str]] = group_order, show_legend: bool = False) -> None
Plot line charts of metrics over runs, colored by Group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame with 'wandb run', metrics, and 'Group'. |
required |
title
|
str
|
Plot title. |
required |
metrics
|
list of str
|
Metric column names to plot. |
required |
save_dir
|
str or None
|
Directory to save plot images. Default is None. |
None
|
group_order
|
list of str or None
|
Order of class labels in the legend. Default is from constants. |
group_order
|
show_legend
|
bool
|
If True, keep the legend; otherwise it will be removed before saving. |
False
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/analysis.py
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 | |
uqdd.metrics.plot_histogram_metrics ¶
plot_histogram_metrics(df: DataFrame, title: str, metrics: List[str], save_dir: Optional[str] = None, group_order: Optional[List[str]] = group_order, cmap: str = 'crest', show_legend: bool = False) -> None
Plot histograms with KDE for metrics, split by Group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame with metrics and 'Group'. |
required |
title
|
str
|
Plot title. |
required |
metrics
|
list of str
|
Metric column names to plot. |
required |
save_dir
|
str or None
|
Directory to save plot images. Default is None. |
None
|
group_order
|
list of str or None
|
Order of class labels in the legend. Default is from constants. |
group_order
|
cmap
|
str
|
Seaborn/matplotlib palette name. Default is "crest". |
'crest'
|
show_legend
|
bool
|
If True, keep the legend; otherwise it will be removed before saving. |
False
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/analysis.py
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 | |
uqdd.metrics.plot_pairwise_scatter_metrics ¶
plot_pairwise_scatter_metrics(df: DataFrame, title: str, metrics: List[str], save_dir: Optional[str] = None, group_order: Optional[List[str]] = group_order, cmap: str = 'tab10_r', show_legend: bool = False) -> None
Plot pairwise scatterplots for all metric combinations, colored by Group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame with metrics and 'Group'. |
required |
title
|
str
|
Plot title. |
required |
metrics
|
list of str
|
Metric column names to plot pairwise. |
required |
save_dir
|
str or None
|
Directory to save plot images. Default is None. |
None
|
group_order
|
list of str or None
|
Order of class labels in the legend. Default is from constants. |
group_order
|
cmap
|
str
|
Matplotlib palette name. Default is "tab10_r". |
'tab10_r'
|
show_legend
|
bool
|
If True, keep the legend; otherwise it will be removed before saving. |
False
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/analysis.py
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 | |
uqdd.metrics.plot_metrics ¶
plot_metrics(df: DataFrame, metrics: List[str], cmap: str = 'tab10_r', save_dir: Optional[str] = None, hatches_dict: Optional[Dict[str, str]] = None, group_order: Optional[List[str]] = None, show: bool = True, fig_width: Optional[float] = None, fig_height: Optional[float] = None, show_legend: bool = False) -> Dict[str, str]
Plot grouped bar charts showing mean and std for metrics across splits and model types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame with columns ['Split', 'Model type'] and metrics. |
required |
metrics
|
list of str
|
Metric column names to plot. |
required |
cmap
|
str
|
Matplotlib colormap name used to derive distinct colors per model type. Default is "tab10_r". |
'tab10_r'
|
save_dir
|
str or None
|
Directory to save plot images. Default is None. |
None
|
hatches_dict
|
dict[str, str] or None
|
Mapping from Split to hatch pattern. Default is None. |
None
|
group_order
|
list of str or None
|
Order of grouped labels (Split_Model type). Default derives from data. |
None
|
show
|
bool
|
If True, display plot in interactive mode. Default is True. |
True
|
fig_width
|
float or None
|
Width of the plot area (excluding legend). Default scales with number of metrics. |
None
|
fig_height
|
float or None
|
Height of the plot area (excluding legend). Default is 6. |
None
|
show_legend
|
bool
|
If True, include a legend of split/model combinations. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Color mapping from 'Model type' to RGBA string used in the plot. |
Source code in uqdd/metrics/analysis.py
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 | |
uqdd.metrics.find_highly_correlated_metrics ¶
find_highly_correlated_metrics(df: DataFrame, metrics: List[str], threshold: float = 0.8, save_dir: Optional[str] = None, cmap: str = 'coolwarm', show_legend: bool = False) -> List[Tuple[str, str, float]]
Identify pairs of metrics with correlation above a threshold and plot the matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame containing the metric columns. |
required |
metrics
|
list of str
|
Metric column names to include in the correlation analysis. |
required |
threshold
|
float
|
Absolute correlation threshold for reporting pairs. Default is 0.8. |
0.8
|
save_dir
|
str or None
|
Directory to save the heatmap plot. Default is None. |
None
|
cmap
|
str
|
Matplotlib colormap name. Default is "coolwarm". |
'coolwarm'
|
show_legend
|
bool
|
If True, keep the legend; otherwise it will be removed before saving. |
False
|
Returns:
| Type | Description |
|---|---|
list of tuple[str, str, float]
|
List of metric pairs and their absolute correlation values. |
Source code in uqdd/metrics/analysis.py
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 | |
uqdd.metrics.plot_comparison_metrics ¶
plot_comparison_metrics(df: DataFrame, metrics: List[str], cmap: str = 'tab10_r', color_dict: Optional[Dict[str, str]] = None, save_dir: Optional[str] = None, fig_width: Optional[float] = None, fig_height: Optional[float] = None, show_legend: bool = False, models_order: Optional[List[str]] = None) -> None
Plot comparison bar charts across splits, model types, and calibration states.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame with columns ['Split', 'Model type', 'Calibration'] and metrics. |
required |
metrics
|
list of str
|
Metric column names to plot. |
required |
cmap
|
str
|
Matplotlib colormap name used to derive distinct colors per model type. Default is "tab10_r". |
'tab10_r'
|
color_dict
|
dict[str, str] or None
|
Precomputed color mapping from model type to color. If None, one is generated. |
None
|
save_dir
|
str or None
|
Directory to save plot images. Default is None. |
None
|
fig_width
|
float or None
|
Width of the plot area (excluding legend). Default scales with the number of metrics. |
None
|
fig_height
|
float or None
|
Height of the plot area (excluding legend). Default is 6. |
None
|
show_legend
|
bool
|
If True, include a legend. Default is False. |
False
|
models_order
|
list of str or None
|
Explicit order of model types for coloring and grouping. Default derives from data. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/analysis.py
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 | |
uqdd.metrics.load_and_aggregate_calibration_data ¶
load_and_aggregate_calibration_data(base_path: str, paths: List[str]) -> Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]
Load calibration curve data from multiple model paths and aggregate statistics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_path
|
str
|
Base directory from which model subpaths are resolved. |
required |
paths
|
list of str
|
Relative paths to model directories containing 'calibration_plot_data.csv'. |
required |
Returns:
| Type | Description |
|---|---|
(ndarray, ndarray, ndarray, ndarray)
|
Tuple of (expected_values, mean_observed, lower_bound, upper_bound), each of shape (n_bins,). |
Source code in uqdd/metrics/analysis.py
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 | |
uqdd.metrics.plot_calibration_data ¶
plot_calibration_data(df_aggregated: DataFrame, base_path: str, save_dir: Optional[str] = None, title: str = 'Calibration Plot', color_name: str = 'tab10_r', color_dict: Optional[Dict[str, str]] = None, group_order: Optional[List[str]] = None, fig_width: Optional[float] = None, fig_height: Optional[float] = None, show_legend: bool = False) -> None
Plot aggregated calibration curves for multiple groups against the perfect calibration line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_aggregated
|
DataFrame
|
Aggregated DataFrame containing 'Group' and 'project_model' lists for each group. |
required |
base_path
|
str
|
Base directory where model paths are located. |
required |
save_dir
|
str or None
|
Directory to save plot images. Default is None. |
None
|
title
|
str
|
Plot title. Default is "Calibration Plot". |
'Calibration Plot'
|
color_name
|
str
|
Colormap name used to derive distinct colors per group. Default is "tab10_r". |
'tab10_r'
|
color_dict
|
dict[str, str] or None
|
Precomputed color mapping from group to color. If None, one is generated. |
None
|
group_order
|
list of str or None
|
Order of groups in the legend. Default derives from data. |
None
|
fig_width
|
float or None
|
Width of the plot area. Default is 6. |
None
|
fig_height
|
float or None
|
Height of the plot area. Default is 6. |
None
|
show_legend
|
bool
|
If True, include a legend. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/analysis.py
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 | |
uqdd.metrics.move_model_folders ¶
move_model_folders(df: DataFrame, search_dirs: List[str], output_dir: str, overwrite: bool = False) -> None
Move or merge model directories into a single output folder based on model names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame containing a 'model name' column. |
required |
search_dirs
|
list of str
|
Directories to search for model subfolders. |
required |
output_dir
|
str
|
Destination directory where model folders will be moved or merged. |
required |
overwrite
|
bool
|
If True, existing folders are merged (copied) with source. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/analysis.py
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 | |
uqdd.metrics.load_predictions ¶
load_predictions(model_path: str) -> pd.DataFrame
Load pickled predictions from a model directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_path
|
str
|
Path to the model directory containing 'preds.pkl'. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame loaded from the pickle file. |
Source code in uqdd/metrics/analysis.py
962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 | |
uqdd.metrics.calculate_rmse_rejection_curve ¶
calculate_rmse_rejection_curve(preds: DataFrame, uncertainty_col: str = 'y_alea', true_label_col: str = 'y_true', pred_label_col: str = 'y_pred', normalize_rmse: bool = False, random_rejection: bool = False, unc_type: Optional[str] = None, max_rejection_ratio: float = 0.95) -> Tuple[np.ndarray, np.ndarray, float]
Compute RMSE vs. rejection rate curve and its AUC by rejecting high-uncertainty predictions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preds
|
DataFrame
|
DataFrame with columns for true labels, predicted labels, and uncertainty components. |
required |
uncertainty_col
|
str
|
Column name for uncertainty to sort by if |
'y_alea'
|
true_label_col
|
str
|
Column name for true labels. Default is "y_true". |
'y_true'
|
pred_label_col
|
str
|
Column name for predicted labels. Default is "y_pred". |
'y_pred'
|
normalize_rmse
|
bool
|
If True, normalize RMSE by the initial RMSE before rejection. Default is False. |
False
|
random_rejection
|
bool
|
If True, randomly reject samples instead of sorting by uncertainty. Default is False. |
False
|
unc_type
|
(aleatoric, epistemic, both)
|
Which uncertainty to use. If "both", sums aleatoric and epistemic. If None, use |
"aleatoric"
|
max_rejection_ratio
|
float
|
Maximum fraction of samples to reject (exclusive of the tail). Default is 0.95. |
0.95
|
Returns:
| Type | Description |
|---|---|
(ndarray, ndarray, float)
|
Tuple of (rejection_rates, rmses, AUC of the RMSE–rejection curve). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in uqdd/metrics/analysis.py
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 | |
uqdd.metrics.calculate_rejection_curve ¶
calculate_rejection_curve(df: DataFrame, model_paths: List[str], unc_col: str, random_rejection: bool = False, normalize_rmse: bool = False, max_rejection_ratio: float = 0.95) -> Tuple[np.ndarray, np.ndarray, np.ndarray, float, float]
Aggregate RMSE–rejection curves across models and compute mean/std and AUC statistics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Auxiliary DataFrame (not used directly, kept for API symmetry). |
required |
model_paths
|
list of str
|
Paths to model directories containing 'preds.pkl'. |
required |
unc_col
|
str
|
Uncertainty column name to use when computing curves (e.g., 'y_alea' or 'y_eps'). |
required |
random_rejection
|
bool
|
If True, randomly reject samples. Default is False. |
False
|
normalize_rmse
|
bool
|
If True, normalize RMSE by the initial RMSE. Default is False. |
False
|
max_rejection_ratio
|
float
|
Maximum fraction of samples to reject. Default is 0.95. |
0.95
|
Returns:
| Type | Description |
|---|---|
(ndarray, ndarray, ndarray, float, float)
|
Tuple of (rejection_rates, mean_rmses, std_rmses, mean_auc, std_auc). |
Source code in uqdd/metrics/analysis.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 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 | |
uqdd.metrics.get_handles_labels ¶
get_handles_labels(ax: Axes, group_order: List[str]) -> Tuple[List, List[str]]
Extract legend handles/labels ordered by group prefix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Axes object from which to retrieve legend entries. |
required |
group_order
|
list of str
|
Group prefixes to order legend entries by. |
required |
Returns:
| Type | Description |
|---|---|
(list, list of str)
|
Ordered handles and labels. |
Source code in uqdd/metrics/analysis.py
1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 | |
uqdd.metrics.plot_rmse_rejection_curves ¶
plot_rmse_rejection_curves(df: DataFrame, base_dir: str, cmap: str = 'tab10_r', color_dict: Optional[Dict[str, str]] = None, save_dir_plot: Optional[str] = None, add_to_title: str = '', normalize_rmse: bool = False, unc_type: str = 'aleatoric', max_rejection_ratio: float = 0.95, group_order: Optional[List[str]] = None, fig_width: Optional[float] = None, fig_height: Optional[float] = None, show_legend: bool = False) -> pd.DataFrame
Plot RMSE–rejection curves per group, including random rejection baselines, and summarize AUCs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame containing columns 'Group', 'Split', and 'project_model'. |
required |
base_dir
|
str
|
Base directory where model paths are located. |
required |
cmap
|
str
|
Colormap name used to derive distinct colors per group. Default is "tab10_r". |
'tab10_r'
|
color_dict
|
dict[str, str] or None
|
Precomputed color mapping from group to color. If None, one is generated. |
None
|
save_dir_plot
|
str or None
|
Directory to save the plot images. Default is None. |
None
|
add_to_title
|
str
|
Suffix for the plot filename and title. Default is empty string. |
''
|
normalize_rmse
|
bool
|
If True, normalize RMSE by initial RMSE. Default is False. |
False
|
unc_type
|
(aleatoric, epistemic, both)
|
Uncertainty component to use for rejection. Default is "aleatoric". |
"aleatoric"
|
max_rejection_ratio
|
float
|
Maximum fraction of samples to reject. Default is 0.95. |
0.95
|
group_order
|
list of str or None
|
Order of groups in the legend. Default derives from data. |
None
|
fig_width
|
float or None
|
Plot width. Default is 6. |
None
|
fig_height
|
float or None
|
Plot height. Default is 6. |
None
|
show_legend
|
bool
|
If True, include a legend. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Summary DataFrame with columns ['Model type', 'Split', 'Group', 'AUC-RRC_mean', 'AUC-RRC_std']. |
Source code in uqdd/metrics/analysis.py
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 | |
uqdd.metrics.plot_auc_comparison ¶
plot_auc_comparison(stats_df: DataFrame, cmap: str = 'tab10_r', color_dict: Optional[Dict[str, str]] = None, save_dir: Optional[str] = None, add_to_title: str = '', min_y_axis: float = 0.0, hatches_dict: Optional[Dict[str, str]] = None, group_order: Optional[List[str]] = None, fig_width: Optional[float] = None, fig_height: Optional[float] = None, show_legend: bool = False) -> None
Plot bar charts comparing RRC-AUC across splits and model types, including random reject baselines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stats_df
|
DataFrame
|
Summary DataFrame with columns ['Group', 'Split', 'Model type', 'AUC-RRC_mean', 'AUC-RRC_std']. |
required |
cmap
|
str
|
Colormap name used to derive distinct colors per model type. Default is "tab10_r". |
'tab10_r'
|
color_dict
|
dict[str, str] or None
|
Precomputed color mapping from model type to color. If None, one is generated. |
None
|
save_dir
|
str or None
|
Directory to save plot images. Default is None. |
None
|
add_to_title
|
str
|
Title suffix for the plot. Default is empty string. |
''
|
min_y_axis
|
float
|
Minimum y-axis limit. Default is 0.0. |
0.0
|
hatches_dict
|
dict[str, str] or None
|
Hatch mapping for splits (e.g., {"stratified": "\"}). Default uses sensible defaults. |
None
|
group_order
|
list of str or None
|
Order of groups in the legend and x-axis. Default derives from data. |
None
|
fig_width
|
float or None
|
Plot width. Default is 6. |
None
|
fig_height
|
float or None
|
Plot height. Default is 6. |
None
|
show_legend
|
bool
|
If True, include a legend. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/analysis.py
1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 | |
uqdd.metrics.save_stats_df ¶
save_stats_df(stats_df: DataFrame, save_dir: str, add_to_title: str = '') -> None
Save a stats DataFrame to CSV in a given directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stats_df
|
DataFrame
|
DataFrame to save. |
required |
save_dir
|
str
|
Target directory to save the CSV. |
required |
add_to_title
|
str
|
Suffix to append to the filename. Default is empty string. |
''
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/analysis.py
1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 | |
uqdd.metrics.load_stats_df ¶
load_stats_df(save_dir: str, add_to_title: str = '') -> pd.DataFrame
Load a stats DataFrame from CSV in a given directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save_dir
|
str
|
Directory containing the CSV. |
required |
add_to_title
|
str
|
Suffix appended to the filename. Default is empty string. |
''
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Loaded DataFrame. |
Source code in uqdd/metrics/analysis.py
1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 | |
uqdd.metrics.calc_regression_metrics ¶
calc_regression_metrics(df, cycle_col, val_col, pred_col, thresh)
Compute regression and thresholded classification metrics per cycle/method/split.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame containing true and predicted values. |
required |
cycle_col
|
str
|
Column name identifying cross-validation cycles. |
required |
val_col
|
str
|
Column with true target values. |
required |
pred_col
|
str
|
Column with predicted target values. |
required |
thresh
|
float
|
Threshold to derive binary classes for precision/recall. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Metrics per (cv_cycle, method, split) with columns ['mae', 'mse', 'r2', 'rho', 'prec', 'recall']. |
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.bootstrap_ci ¶
bootstrap_ci(data, func=np.mean, n_bootstrap=1000, ci=95, random_state=42)
Compute bootstrap confidence interval for a statistic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
array - like
|
Sequence of numeric values. |
required |
func
|
callable
|
Statistic function applied to bootstrap samples (e.g., numpy.mean). Default is numpy.mean. |
mean
|
n_bootstrap
|
int
|
Number of bootstrap resamples. Default is 1000. |
1000
|
ci
|
int or float
|
Confidence level percentage (e.g., 95). Default is 95. |
95
|
random_state
|
int
|
Seed for reproducibility. Default is 42. |
42
|
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Lower and upper bounds for the confidence interval. |
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.rm_tukey_hsd ¶
rm_tukey_hsd(df, metric, group_col, alpha=0.05, sort=False, direction_dict=None)
Repeated-measures Tukey HSD approximation using RM-ANOVA and studentized range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Long-form DataFrame with columns including the metric, group, and 'cv_cycle' subject. |
required |
metric
|
str
|
Metric column to compare. |
required |
group_col
|
str
|
Column indicating groups (e.g., method/model type). |
required |
alpha
|
float
|
Family-wise error rate for intervals. Default is 0.05. |
0.05
|
sort
|
bool
|
If True, sort groups by mean value of the metric. Default is False. |
False
|
direction_dict
|
dict or None
|
Mapping of metric -> 'maximize'|'minimize' to set sort ascending/descending. |
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
(result_tab, df_means, df_means_diff, p_values_matrix) where: - result_tab: DataFrame of pairwise comparisons with mean differences and CIs. - df_means: mean per group. - df_means_diff: matrix of mean differences. - pc: matrix of adjusted p-values. |
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.make_boxplots ¶
make_boxplots(df, metric_ls, save_dir=None, name_prefix='', model_order=None)
Plot boxplots for each metric grouped by method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. |
required |
metric_ls
|
list of str
|
Metrics to visualize. |
required |
save_dir
|
str or None
|
Directory to save the plot. Default is None. |
None
|
name_prefix
|
str
|
Prefix for the output filename. Default is empty. |
''
|
model_order
|
list of str or None
|
Explicit order of methods on the x-axis. Default derives from data. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.make_boxplots_parametric ¶
make_boxplots_parametric(df, metric_ls, save_dir=None, name_prefix='', model_order=None)
Plot boxplots with RM-ANOVA p-values annotated per metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. |
required |
metric_ls
|
list of str
|
Metrics to visualize. |
required |
save_dir
|
str or None
|
Directory to save the plot. Default is None. |
None
|
name_prefix
|
str
|
Prefix for the output filename. Default is empty. |
''
|
model_order
|
list of str or None
|
Explicit order of methods on the x-axis. Default derives from data. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.make_boxplots_nonparametric ¶
make_boxplots_nonparametric(df, metric_ls, save_dir=None, name_prefix='', model_order=None)
Plot boxplots with Friedman p-values annotated per metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. |
required |
metric_ls
|
list of str
|
Metrics to visualize. |
required |
save_dir
|
str or None
|
Directory to save the plot. Default is None. |
None
|
name_prefix
|
str
|
Prefix for the output filename. Default is empty. |
''
|
model_order
|
list of str or None
|
Explicit order of methods on the x-axis. Default derives from data. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.make_sign_plots_nonparametric ¶
make_sign_plots_nonparametric(df, metric_ls, save_dir=None, name_prefix='', model_order=None)
Plot significance heatmaps (Conover post-hoc) for nonparametric comparisons.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. |
required |
metric_ls
|
list of str
|
Metrics to analyze. |
required |
save_dir
|
str or None
|
Directory to save the plot. Default is None. |
None
|
name_prefix
|
str
|
Prefix for the output filename. Default is empty. |
''
|
model_order
|
list of str or None
|
Explicit order of methods on axes. Default derives from data. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.make_critical_difference_diagrams ¶
make_critical_difference_diagrams(df, metric_ls, save_dir=None, name_prefix='', model_order=None)
Plot critical difference diagrams per metric using average ranks and post-hoc p-values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. |
required |
metric_ls
|
list of str
|
Metrics to analyze. |
required |
save_dir
|
str or None
|
Directory to save the plot. Default is None. |
None
|
name_prefix
|
str
|
Prefix for the output filename. Default is empty. |
''
|
model_order
|
list of str or None
|
Explicit order of models on diagrams. Default derives from data. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.make_normality_diagnostic ¶
make_normality_diagnostic(df, metric_ls, save_dir=None, name_prefix='')
Plot normality diagnostics (histogram/KDE and Q-Q) for residualized metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. |
required |
metric_ls
|
list of str
|
Metrics to diagnose. |
required |
save_dir
|
str or None
|
Directory to save the plot. Default is None. |
None
|
name_prefix
|
str
|
Prefix for the output filename. Default is empty. |
''
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.mcs_plot ¶
mcs_plot(pc, effect_size, means, labels=True, cmap=None, cbar_ax_bbox=None, ax=None, show_diff=True, cell_text_size=10, axis_text_size=8, show_cbar=True, reverse_cmap=False, vlim=None, **kwargs)
Render a multiple-comparisons significance heatmap annotated with effect sizes and stars.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pc
|
DataFrame
|
Matrix of adjusted p-values. |
required |
effect_size
|
DataFrame
|
Matrix of mean differences (effect sizes) aligned with |
required |
means
|
Series
|
Mean values per group for labeling. |
required |
labels
|
bool
|
If True, add x/y tick labels from |
True
|
cmap
|
str or None
|
Colormap name for effect sizes. Default is 'YlGnBu'. |
None
|
cbar_ax_bbox
|
tuple or None
|
Custom colorbar axes bbox; unused here but kept for API compatibility. |
None
|
ax
|
Axes or None
|
Axes to draw into; if None, a new axes is created. |
None
|
show_diff
|
bool
|
If True, annotate cells with rounded effect sizes plus significance. Default is True. |
True
|
cell_text_size
|
int
|
Font size for annotations. Default is 10. |
10
|
axis_text_size
|
int
|
Font size for axis tick labels. Default is 8. |
8
|
show_cbar
|
bool
|
If True, show colorbar. Default is True. |
True
|
reverse_cmap
|
bool
|
If True, use reversed colormap. Default is False. |
False
|
vlim
|
float or None
|
Symmetric limit for color scaling around 0. Default is None. |
None
|
Returns:
| Type | Description |
|---|---|
Axes
|
Axes containing the rendered heatmap. |
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.make_mcs_plot_grid ¶
make_mcs_plot_grid(df, stats_list, group_col, alpha=0.05, figsize=(20, 10), direction_dict=None, effect_dict=None, show_diff=True, cell_text_size=16, axis_text_size=12, title_text_size=16, sort_axes=False, save_dir=None, name_prefix='', model_order=None)
Generate a grid of MCS plots for multiple metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. |
required |
stats_list
|
list of str
|
Metrics to include. |
required |
group_col
|
str
|
Column indicating groups (e.g., method). |
required |
alpha
|
float
|
Significance level. Default is 0.05. |
0.05
|
figsize
|
tuple
|
Figure size. Default is (20, 10). |
(20, 10)
|
direction_dict
|
dict or None
|
Mapping metric -> 'maximize'|'minimize' for colormap orientation. |
None
|
effect_dict
|
dict or None
|
Mapping metric -> effect size limit for color scaling. |
None
|
show_diff
|
bool
|
If True, annotate mean differences; else annotate significance only. |
True
|
cell_text_size
|
int
|
Annotation font size. |
16
|
axis_text_size
|
int
|
Axis label font size. |
12
|
title_text_size
|
int
|
Title font size. |
16
|
sort_axes
|
bool
|
If True, sort groups by mean values per metric. |
False
|
save_dir
|
str or None
|
Directory to save the plot. Default is None. |
None
|
name_prefix
|
str
|
Filename prefix. Default is empty. |
''
|
model_order
|
list of str or None
|
Explicit model order for rows/cols. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.make_scatterplot ¶
make_scatterplot(df, val_col, pred_col, thresh, cycle_col='cv_cycle', group_col='method', save_dir=None)
Scatter plots of predicted vs true values per method, with threshold lines and summary stats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. |
required |
val_col
|
str
|
True value column. |
required |
pred_col
|
str
|
Predicted value column. |
required |
thresh
|
float
|
Threshold for classification overlays. |
required |
cycle_col
|
str
|
Cross-validation cycle column. Default is 'cv_cycle'. |
'cv_cycle'
|
group_col
|
str
|
Method/model type column. Default is 'method'. |
'method'
|
save_dir
|
str or None
|
Directory to save the plot. Default is None. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.ci_plot ¶
ci_plot(result_tab, ax_in, name)
Plot mean differences with confidence intervals for pairwise comparisons.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result_tab
|
DataFrame
|
Output of rm_tukey_hsd with columns ['meandiff', 'lower', 'upper']. |
required |
ax_in
|
Axes
|
Axes to plot into. |
required |
name
|
str
|
Title for the plot. |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.make_ci_plot_grid ¶
make_ci_plot_grid(df_in, metric_list, group_col='method', save_dir=None, name_prefix='', model_order=None)
Plot a grid of confidence-interval charts for multiple metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_in
|
DataFrame
|
Input DataFrame. |
required |
metric_list
|
list of str
|
Metrics to render. |
required |
group_col
|
str
|
Group column (e.g., 'method'). Default is 'method'. |
'method'
|
save_dir
|
str or None
|
Directory to save the plot. Default is None. |
None
|
name_prefix
|
str
|
Filename prefix. Default is empty. |
''
|
model_order
|
list of str or None
|
Explicit row order for the CI plots. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.recall_at_precision ¶
recall_at_precision(y_true, y_score, precision_threshold=0.5, direction='greater')
Find recall and threshold achieving at least a target precision.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
array - like
|
Binary ground-truth labels. |
required |
y_score
|
array - like
|
Continuous scores or probabilities. |
required |
precision_threshold
|
float
|
Minimum precision to achieve. Default is 0.5. |
0.5
|
direction
|
(greater, lesser)
|
If 'greater', thresholding uses >=; if 'lesser', uses <=. Default is 'greater'. |
"greater"
|
Returns:
| Type | Description |
|---|---|
tuple[float, float or None]
|
(recall, threshold) if achievable; otherwise (nan, None). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.calc_classification_metrics ¶
calc_classification_metrics(df_in, cycle_col, val_col, prob_col, pred_col)
Compute classification metrics per cycle/method/split, including ROC-AUC, PR-AUC, MCC, recall, and TNR.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_in
|
DataFrame
|
Input DataFrame. |
required |
cycle_col
|
str
|
Column name for cross-validation cycles. |
required |
val_col
|
str
|
True binary label column. |
required |
prob_col
|
str
|
Predicted probability/score column. |
required |
pred_col
|
str
|
Predicted binary label column. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Metrics per (cv_cycle, method, split) with columns ['roc_auc', 'pr_auc', 'mcc', 'recall', 'tnr']. |
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.make_curve_plots ¶
make_curve_plots(df)
Plot ROC and PR curves for split/method selections with threshold markers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame containing 'cv_cycle', 'split', and method columns plus true/probability fields. |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.harmonize_columns ¶
harmonize_columns(df)
Normalize common column names to ['method', 'split', 'cv_cycle'].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame with possibly varied column naming. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with standardized column names and assertion that required columns exist. |
Source code in uqdd/metrics/stats.py
872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 | |
uqdd.metrics.cliffs_delta ¶
cliffs_delta(x, y)
Compute Cliff's delta effect size and qualitative interpretation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array - like
|
First sample of numeric values. |
required |
y
|
array - like
|
Second sample of numeric values. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, str]
|
(delta, interpretation) where interpretation is one of {'negligible','small','medium','large'}. |
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.wilcoxon_pairwise_test ¶
wilcoxon_pairwise_test(df, metric, model_a, model_b, task=None, split=None, seed_col=None)
Perform paired Wilcoxon signed-rank test between two models on a metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. |
required |
metric
|
str
|
Metric column to compare. |
required |
model_a
|
str
|
First model type name. |
required |
model_b
|
str
|
Second model type name. |
required |
task
|
str or None
|
Task filter. Default is None. |
None
|
split
|
str or None
|
Split filter. Default is None. |
None
|
seed_col
|
str or None
|
Optional seed column identifier (unused here). |
None
|
Returns:
| Type | Description |
|---|---|
dict or None
|
Test summary including statistic, p-value, Cliff's delta, CI on differences; None if insufficient data. |
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.holm_bonferroni_correction ¶
holm_bonferroni_correction(p_values)
Apply Holm–Bonferroni correction to an array of p-values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p_values
|
array - like
|
Raw p-values. |
required |
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray]
|
(corrected_p_values, rejected_mask) where rejected indicates significance after correction. |
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.pairwise_model_comparison ¶
pairwise_model_comparison(df, metrics, models=None, tasks=None, splits=None, alpha=0.05)
Run pairwise Wilcoxon tests across models/tasks/splits for multiple metrics and adjust p-values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. |
required |
metrics
|
list of str
|
Metrics to compare. |
required |
models
|
list of str or None
|
Models to include; default derives from data. |
None
|
tasks
|
list of str or None
|
Tasks to include; default derives from data. |
None
|
splits
|
list of str or None
|
Splits to include; default derives from data. |
None
|
alpha
|
float
|
Significance level. Default is 0.05. |
0.05
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Results table with corrected p-values and significance flags. |
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.friedman_nemenyi_test ¶
friedman_nemenyi_test(df, metrics, models=None, alpha=0.05)
Run Friedman test across models with Nemenyi post-hoc where significant, per metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. |
required |
metrics
|
list of str
|
Metrics to test. |
required |
models
|
list of str or None
|
Models to include; default derives from data. |
None
|
alpha
|
float
|
Significance level. Default is 0.05. |
0.05
|
Returns:
| Type | Description |
|---|---|
dict
|
Mapping metric -> result dict containing stats, p-values, mean ranks, and optional post-hoc outputs. |
Source code in uqdd/metrics/stats.py
1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 | |
uqdd.metrics.calculate_critical_difference ¶
calculate_critical_difference(k, n, alpha=0.05)
Compute the critical difference for average ranks in Nemenyi post-hoc tests.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
int
|
Number of models. |
required |
n
|
int
|
Number of datasets/blocks. |
required |
alpha
|
float
|
Significance level. Default is 0.05. |
0.05
|
Returns:
| Type | Description |
|---|---|
float
|
Critical difference value. |
Source code in uqdd/metrics/stats.py
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 | |
uqdd.metrics.bootstrap_auc_difference ¶
bootstrap_auc_difference(auc_values_a, auc_values_b, n_bootstrap=1000, ci=95, random_state=42)
Bootstrap confidence interval for difference of mean AUCs between two models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
auc_values_a
|
array - like
|
AUC values for model A. |
required |
auc_values_b
|
array - like
|
AUC values for model B. |
required |
n_bootstrap
|
int
|
Number of bootstrap resamples. Default is 1000. |
1000
|
ci
|
int or float
|
Confidence level in percent. Default is 95. |
95
|
random_state
|
int
|
Seed for reproducibility. Default is 42. |
42
|
Returns:
| Type | Description |
|---|---|
dict
|
{'mean_difference', 'ci_lower', 'ci_upper', 'bootstrap_differences'} |
Source code in uqdd/metrics/stats.py
1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 | |
uqdd.metrics.plot_critical_difference_diagram ¶
plot_critical_difference_diagram(friedman_results, metric, save_dir=None, alpha=0.05)
Plot a simple critical difference diagram using mean ranks and CD value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
friedman_results
|
dict
|
Output dictionary from friedman_nemenyi_test. |
required |
metric
|
str
|
Metric to plot. |
required |
save_dir
|
str or None
|
Directory to save the plot. Default is None. |
None
|
alpha
|
float
|
Significance level used to compute CD. Default is 0.05. |
0.05
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/stats.py
1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 | |
uqdd.metrics.analyze_significance ¶
analyze_significance(df_raw, metrics, direction_dict, effect_dict, save_dir=None, model_order=None, activity=None)
End-to-end significance analysis and plotting across splits for multiple metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_raw
|
DataFrame
|
Raw results DataFrame. |
required |
metrics
|
list of str
|
Metric names to analyze. |
required |
direction_dict
|
dict
|
Mapping metric -> 'maximize'|'minimize'. |
required |
effect_dict
|
dict
|
Mapping metric -> effect size threshold for visualization. |
required |
save_dir
|
str or None
|
Directory to save plots and outputs. Default is None. |
None
|
model_order
|
list of str or None
|
Explicit ordering of models. Default derives from data. |
None
|
activity
|
str or None
|
Activity name for prefixes. Default is None. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/stats.py
1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 | |
uqdd.metrics.comprehensive_statistical_analysis ¶
comprehensive_statistical_analysis(df, metrics, models=None, tasks=None, splits=None, save_dir=None, alpha=0.05)
Run a comprehensive suite of statistical tests and export results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. |
required |
metrics
|
list of str
|
Metrics to analyze. |
required |
models
|
list of str or None
|
Models to include. Default derives from data. |
None
|
tasks
|
list of str or None
|
Tasks to include. Default derives from data. |
None
|
splits
|
list of str or None
|
Splits to include. Default derives from data. |
None
|
save_dir
|
str or None
|
Directory to save tables and JSON outputs. Default is None. |
None
|
alpha
|
float
|
Significance level. Default is 0.05. |
0.05
|
Returns:
| Type | Description |
|---|---|
dict
|
Results dict including pairwise tests, Friedman/Nemenyi outputs, and optional AUC bootstrap comparisons. |
Source code in uqdd/metrics/stats.py
1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 | |
uqdd.metrics.generate_statistical_report ¶
generate_statistical_report(results, save_dir=None, df_raw=None, metrics=None, direction_dict=None, effect_dict=None)
Generate a human-readable text report from comprehensive statistical results and optionally run plots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
dict
|
Output of comprehensive_statistical_analysis. |
required |
save_dir
|
str or None
|
Directory to save the report text file. Default is None. |
None
|
df_raw
|
DataFrame or None
|
Raw DataFrame to run plotting-based significance analysis. Default is None. |
None
|
metrics
|
list of str or None
|
Metrics to plot (when df_raw provided). |
None
|
direction_dict
|
dict or None
|
Direction mapping for metrics (required when df_raw provided). |
None
|
effect_dict
|
dict or None
|
Effect threshold mapping (required when df_raw provided). |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Report text. |
Source code in uqdd/metrics/stats.py
1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 | |
uqdd.metrics.nll_evidentials ¶
nll_evidentials(evidential_model, test_dataloader, model_type: str = 'evidential', num_mc_samples: int = 100, device=DEVICE)
Compute negative log-likelihood (NLL) for evidential-style models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
evidential_model
|
Module
|
Trained model instance. |
required |
test_dataloader
|
DataLoader
|
DataLoader providing test set batches. |
required |
model_type
|
(evidential, eoe, emc)
|
Model family determining the NLL backend. Default is "evidential". |
"evidential"
|
num_mc_samples
|
int
|
Number of MC samples for EMC models. Default is 100. |
100
|
device
|
device
|
Device to run evaluation on. Default uses |
DEVICE
|
Returns:
| Type | Description |
|---|---|
float or None
|
Scalar NLL if supported by the model type; None otherwise. |
Source code in uqdd/metrics/reassessment.py
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 | |
uqdd.metrics.convert_to_list ¶
convert_to_list(val)
Parse a string representation of a Python list to a list; pass through non-strings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
val
|
str or any
|
Input value, possibly a string encoding of a list. |
required |
Returns:
| Type | Description |
|---|---|
list
|
Parsed list if |
any
|
Original value if not a string. |
Notes
- Uses
ast.literal_evalfor safe evaluation. - Prints a warning and returns [] when parsing fails.
Source code in uqdd/metrics/reassessment.py
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 | |
uqdd.metrics.preprocess_runs ¶
preprocess_runs(runs_path: str, models_dir: str = MODELS_DIR, data_name: str = 'papyrus', activity_type: str = 'xc50', descriptor_protein: str = 'ankh-large', descriptor_chemical: str = 'ecfp2048', data_specific_path: str = 'papyrus/xc50/all', prot_input_dim: int = 1536, chem_input_dim: int = 2048) -> pd.DataFrame
Read a runs CSV and enrich with resolved model paths and descriptor metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runs_path
|
str
|
Path to the CSV file containing run metadata. |
required |
models_dir
|
str
|
Directory containing trained model .pt files. Default uses |
MODELS_DIR
|
data_name
|
str
|
Dataset identifier. Default is "papyrus". |
'papyrus'
|
activity_type
|
str
|
Activity type (e.g., "xc50", "kc"). Default is "xc50". |
'xc50'
|
descriptor_protein
|
str
|
Protein descriptor type. Default is "ankh-large". |
'ankh-large'
|
descriptor_chemical
|
str
|
Chemical descriptor type. Default is "ecfp2048". |
'ecfp2048'
|
data_specific_path
|
str
|
Subpath encoding dataset context for figures/exports. Default is "papyrus/xc50/all". |
'papyrus/xc50/all'
|
prot_input_dim
|
int
|
Protein input dimensionality. Default is 1536. |
1536
|
chem_input_dim
|
int
|
Chemical input dimensionality. Default is 2048. |
2048
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Preprocessed runs DataFrame with columns like 'model_name', 'model_path', and descriptor fields. |
Notes
- Resolves
model_nameto actual .pt files via glob and sets 'model_path'. - Adds multi-task flag 'MT' from 'n_targets' > 1.
- Converts layer columns from strings to lists using
convert_to_list.
Source code in uqdd/metrics/reassessment.py
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 | |
uqdd.metrics.get_model_class ¶
get_model_class(model_type: str)
Map a model type name to the corresponding class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_type
|
str
|
Model type identifier (e.g., "pnn", "ensemble", "evidential", "eoe", "emc", "mcdropout"). |
required |
Returns:
| Type | Description |
|---|---|
type
|
Model class matching the type. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the |
Source code in uqdd/metrics/reassessment.py
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 | |
uqdd.metrics.get_predict_fn ¶
get_predict_fn(model_type: str, num_mc_samples: int = 100)
Get the appropriate predict function and kwargs for a given model type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_type
|
str
|
Model type identifier. |
required |
num_mc_samples
|
int
|
Number of MC samples for MC Dropout or EMC models. Default is 100. |
100
|
Returns:
| Type | Description |
|---|---|
(callable, dict)
|
Tuple of (predict_function, keyword_arguments). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the |
Source code in uqdd/metrics/reassessment.py
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 | |
uqdd.metrics.get_preds ¶
get_preds(model, dataloaders, model_type: str, subset: str = 'test', num_mc_samples: int = 100)
Run inference and unpack predictions for the requested subset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
Trained model instance. |
required |
dataloaders
|
dict
|
Dictionary of DataLoaders keyed by subset (e.g., 'train', 'val', 'test'). |
required |
model_type
|
str
|
Model type determining the predict function and outputs. |
required |
subset
|
str
|
Subset key to use from |
'test'
|
num_mc_samples
|
int
|
Number of MC samples for stochastic predictors. Default is 100. |
100
|
Returns:
| Type | Description |
|---|---|
tuple
|
(preds, labels, alea_vars, epi_vars) where |
Source code in uqdd/metrics/reassessment.py
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 | |
uqdd.metrics.pkl_preds_export ¶
pkl_preds_export(preds, labels, alea_vars, epi_vars, outpath: str, model_type: str, logger=None)
Export predictions and uncertainties to a standardized pickle and return the DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preds
|
ndarray or Tensor
|
Model predictions. |
required |
labels
|
ndarray or Tensor
|
True labels. |
required |
alea_vars
|
ndarray or Tensor
|
Aleatoric uncertainty components. |
required |
epi_vars
|
ndarray or Tensor or None
|
Epistemic uncertainty components, or None for non-evidential models. |
required |
outpath
|
str
|
Output directory to write 'preds.pkl'. |
required |
model_type
|
str
|
Model type used to guide |
required |
logger
|
Logger or None
|
Logger for messages. Default is None. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with columns [y_true, y_pred, y_err, y_alea, y_eps]. |
Source code in uqdd/metrics/reassessment.py
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 | |
uqdd.metrics.csv_nll_post_processing ¶
csv_nll_post_processing(csv_path: str) -> None
Normalize NLL values in a CSV by taking the first value per model name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
csv_path
|
str
|
Path to the CSV file containing a 'model name' and 'NLL' column. |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/reassessment.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
uqdd.metrics.reassess_metrics ¶
reassess_metrics(runs_df: DataFrame, figs_out_path: str, csv_out_path: str, project_out_name: str, logger) -> None
Reassess metrics for each run: reload model, predict, compute NLL, evaluate, and recalibrate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runs_df
|
DataFrame
|
Preprocessed runs DataFrame with resolved 'model_path' and configuration fields. |
required |
figs_out_path
|
str
|
Directory where per-model figures and prediction pickles are saved. |
required |
csv_out_path
|
str
|
Path to a CSV for logging metrics (passed to |
required |
project_out_name
|
str
|
Name used for grouping results in downstream logging. |
required |
logger
|
Logger
|
Logger instance used through evaluation and recalibration. |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Notes
- Skips models already reassessed when a figure directory exists.
- Uses validation split for isotonic recalibration and logs final metrics.
Source code in uqdd/metrics/reassessment.py
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 | |
uqdd.metrics.analysis ¶
Analysis and plotting utilities for model metrics.
This module provides functions to aggregate experiment results, compute summary statistics, and visualize metrics via pairplots, line plots, histograms, bar plots, correlation matrices, calibration curves, and RMSE rejection curves.
uqdd.metrics.analysis.aggregate_results_csv ¶
aggregate_results_csv(df: DataFrame, group_cols: List[str], numeric_cols: List[str], string_cols: List[str], order_by: Optional[Union[str, List[str]]] = None, output_file_path: Optional[str] = None) -> pd.DataFrame
Aggregate metrics by groups and export a compact CSV summary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input results DataFrame. |
required |
group_cols
|
list of str
|
Column names to group by. |
required |
numeric_cols
|
list of str
|
Numeric metric columns to aggregate with mean and std. |
required |
string_cols
|
list of str
|
String columns to aggregate as lists. |
required |
order_by
|
str or list of str or None
|
Column(s) to sort the final aggregated DataFrame by. Default is None. |
None
|
output_file_path
|
str or None
|
Path to write the aggregated CSV. If None, no file is written. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Aggregated DataFrame with combined mean(std) strings plus string/list aggregates. |
Notes
- A helper column
project_modelis constructed and included in the aggregates. - When
output_file_pathis provided, the function ensures the directory exists.
Source code in uqdd/metrics/analysis.py
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 | |
uqdd.metrics.analysis.save_plot ¶
save_plot(fig: Figure, save_dir: Optional[str], plot_name: str, tighten: bool = True, show_legend: bool = False) -> None
Save a matplotlib figure to PNG, SVG, and PDF with optional tight layout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig
|
Figure
|
Figure to save. |
required |
save_dir
|
str or None
|
Directory to save the figure files. If None, no files are written. |
required |
plot_name
|
str
|
Base filename (without extension). |
required |
tighten
|
bool
|
If True, apply tight_layout and bbox_inches="tight". Default is True. |
True
|
show_legend
|
bool
|
If False, remove legend before saving. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/analysis.py
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 | |
uqdd.metrics.analysis.handle_inf_values ¶
handle_inf_values(df: DataFrame) -> pd.DataFrame
Replace +/- infinity values in a DataFrame with NaN.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with infinite values replaced by NaN. |
Source code in uqdd/metrics/analysis.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
uqdd.metrics.analysis.plot_pairplot ¶
plot_pairplot(df: DataFrame, title: str, metrics: List[str], save_dir: Optional[str] = None, cmap: str = 'viridis', group_order: Optional[List[str]] = group_order, show_legend: bool = False) -> None
Plot a seaborn pairplot for a set of metrics colored by Group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame containing the metrics and a 'Group' column. |
required |
title
|
str
|
Plot title. |
required |
metrics
|
list of str
|
Metric column names to include in the pairplot. |
required |
save_dir
|
str or None
|
Directory to save plot images. Default is None. |
None
|
cmap
|
str
|
Seaborn/matplotlib palette name. Default is "viridis". |
'viridis'
|
group_order
|
list of str or None
|
Order of class labels in the legend. Default is from constants. |
group_order
|
show_legend
|
bool
|
If True, keep the legend; otherwise it will be removed before saving. |
False
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/analysis.py
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 | |
uqdd.metrics.analysis.plot_line_metrics ¶
plot_line_metrics(df: DataFrame, title: str, metrics: List[str], save_dir: Optional[str] = None, group_order: Optional[List[str]] = group_order, show_legend: bool = False) -> None
Plot line charts of metrics over runs, colored by Group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame with 'wandb run', metrics, and 'Group'. |
required |
title
|
str
|
Plot title. |
required |
metrics
|
list of str
|
Metric column names to plot. |
required |
save_dir
|
str or None
|
Directory to save plot images. Default is None. |
None
|
group_order
|
list of str or None
|
Order of class labels in the legend. Default is from constants. |
group_order
|
show_legend
|
bool
|
If True, keep the legend; otherwise it will be removed before saving. |
False
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/analysis.py
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 | |
uqdd.metrics.analysis.plot_histogram_metrics ¶
plot_histogram_metrics(df: DataFrame, title: str, metrics: List[str], save_dir: Optional[str] = None, group_order: Optional[List[str]] = group_order, cmap: str = 'crest', show_legend: bool = False) -> None
Plot histograms with KDE for metrics, split by Group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame with metrics and 'Group'. |
required |
title
|
str
|
Plot title. |
required |
metrics
|
list of str
|
Metric column names to plot. |
required |
save_dir
|
str or None
|
Directory to save plot images. Default is None. |
None
|
group_order
|
list of str or None
|
Order of class labels in the legend. Default is from constants. |
group_order
|
cmap
|
str
|
Seaborn/matplotlib palette name. Default is "crest". |
'crest'
|
show_legend
|
bool
|
If True, keep the legend; otherwise it will be removed before saving. |
False
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/analysis.py
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 | |
uqdd.metrics.analysis.plot_pairwise_scatter_metrics ¶
plot_pairwise_scatter_metrics(df: DataFrame, title: str, metrics: List[str], save_dir: Optional[str] = None, group_order: Optional[List[str]] = group_order, cmap: str = 'tab10_r', show_legend: bool = False) -> None
Plot pairwise scatterplots for all metric combinations, colored by Group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame with metrics and 'Group'. |
required |
title
|
str
|
Plot title. |
required |
metrics
|
list of str
|
Metric column names to plot pairwise. |
required |
save_dir
|
str or None
|
Directory to save plot images. Default is None. |
None
|
group_order
|
list of str or None
|
Order of class labels in the legend. Default is from constants. |
group_order
|
cmap
|
str
|
Matplotlib palette name. Default is "tab10_r". |
'tab10_r'
|
show_legend
|
bool
|
If True, keep the legend; otherwise it will be removed before saving. |
False
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/analysis.py
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 | |
uqdd.metrics.analysis.plot_metrics ¶
plot_metrics(df: DataFrame, metrics: List[str], cmap: str = 'tab10_r', save_dir: Optional[str] = None, hatches_dict: Optional[Dict[str, str]] = None, group_order: Optional[List[str]] = None, show: bool = True, fig_width: Optional[float] = None, fig_height: Optional[float] = None, show_legend: bool = False) -> Dict[str, str]
Plot grouped bar charts showing mean and std for metrics across splits and model types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame with columns ['Split', 'Model type'] and metrics. |
required |
metrics
|
list of str
|
Metric column names to plot. |
required |
cmap
|
str
|
Matplotlib colormap name used to derive distinct colors per model type. Default is "tab10_r". |
'tab10_r'
|
save_dir
|
str or None
|
Directory to save plot images. Default is None. |
None
|
hatches_dict
|
dict[str, str] or None
|
Mapping from Split to hatch pattern. Default is None. |
None
|
group_order
|
list of str or None
|
Order of grouped labels (Split_Model type). Default derives from data. |
None
|
show
|
bool
|
If True, display plot in interactive mode. Default is True. |
True
|
fig_width
|
float or None
|
Width of the plot area (excluding legend). Default scales with number of metrics. |
None
|
fig_height
|
float or None
|
Height of the plot area (excluding legend). Default is 6. |
None
|
show_legend
|
bool
|
If True, include a legend of split/model combinations. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Color mapping from 'Model type' to RGBA string used in the plot. |
Source code in uqdd/metrics/analysis.py
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 | |
uqdd.metrics.analysis.find_highly_correlated_metrics ¶
find_highly_correlated_metrics(df: DataFrame, metrics: List[str], threshold: float = 0.8, save_dir: Optional[str] = None, cmap: str = 'coolwarm', show_legend: bool = False) -> List[Tuple[str, str, float]]
Identify pairs of metrics with correlation above a threshold and plot the matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame containing the metric columns. |
required |
metrics
|
list of str
|
Metric column names to include in the correlation analysis. |
required |
threshold
|
float
|
Absolute correlation threshold for reporting pairs. Default is 0.8. |
0.8
|
save_dir
|
str or None
|
Directory to save the heatmap plot. Default is None. |
None
|
cmap
|
str
|
Matplotlib colormap name. Default is "coolwarm". |
'coolwarm'
|
show_legend
|
bool
|
If True, keep the legend; otherwise it will be removed before saving. |
False
|
Returns:
| Type | Description |
|---|---|
list of tuple[str, str, float]
|
List of metric pairs and their absolute correlation values. |
Source code in uqdd/metrics/analysis.py
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 | |
uqdd.metrics.analysis.plot_comparison_metrics ¶
plot_comparison_metrics(df: DataFrame, metrics: List[str], cmap: str = 'tab10_r', color_dict: Optional[Dict[str, str]] = None, save_dir: Optional[str] = None, fig_width: Optional[float] = None, fig_height: Optional[float] = None, show_legend: bool = False, models_order: Optional[List[str]] = None) -> None
Plot comparison bar charts across splits, model types, and calibration states.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame with columns ['Split', 'Model type', 'Calibration'] and metrics. |
required |
metrics
|
list of str
|
Metric column names to plot. |
required |
cmap
|
str
|
Matplotlib colormap name used to derive distinct colors per model type. Default is "tab10_r". |
'tab10_r'
|
color_dict
|
dict[str, str] or None
|
Precomputed color mapping from model type to color. If None, one is generated. |
None
|
save_dir
|
str or None
|
Directory to save plot images. Default is None. |
None
|
fig_width
|
float or None
|
Width of the plot area (excluding legend). Default scales with the number of metrics. |
None
|
fig_height
|
float or None
|
Height of the plot area (excluding legend). Default is 6. |
None
|
show_legend
|
bool
|
If True, include a legend. Default is False. |
False
|
models_order
|
list of str or None
|
Explicit order of model types for coloring and grouping. Default derives from data. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/analysis.py
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 | |
uqdd.metrics.analysis.load_and_aggregate_calibration_data ¶
load_and_aggregate_calibration_data(base_path: str, paths: List[str]) -> Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]
Load calibration curve data from multiple model paths and aggregate statistics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_path
|
str
|
Base directory from which model subpaths are resolved. |
required |
paths
|
list of str
|
Relative paths to model directories containing 'calibration_plot_data.csv'. |
required |
Returns:
| Type | Description |
|---|---|
(ndarray, ndarray, ndarray, ndarray)
|
Tuple of (expected_values, mean_observed, lower_bound, upper_bound), each of shape (n_bins,). |
Source code in uqdd/metrics/analysis.py
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 | |
uqdd.metrics.analysis.plot_calibration_data ¶
plot_calibration_data(df_aggregated: DataFrame, base_path: str, save_dir: Optional[str] = None, title: str = 'Calibration Plot', color_name: str = 'tab10_r', color_dict: Optional[Dict[str, str]] = None, group_order: Optional[List[str]] = None, fig_width: Optional[float] = None, fig_height: Optional[float] = None, show_legend: bool = False) -> None
Plot aggregated calibration curves for multiple groups against the perfect calibration line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_aggregated
|
DataFrame
|
Aggregated DataFrame containing 'Group' and 'project_model' lists for each group. |
required |
base_path
|
str
|
Base directory where model paths are located. |
required |
save_dir
|
str or None
|
Directory to save plot images. Default is None. |
None
|
title
|
str
|
Plot title. Default is "Calibration Plot". |
'Calibration Plot'
|
color_name
|
str
|
Colormap name used to derive distinct colors per group. Default is "tab10_r". |
'tab10_r'
|
color_dict
|
dict[str, str] or None
|
Precomputed color mapping from group to color. If None, one is generated. |
None
|
group_order
|
list of str or None
|
Order of groups in the legend. Default derives from data. |
None
|
fig_width
|
float or None
|
Width of the plot area. Default is 6. |
None
|
fig_height
|
float or None
|
Height of the plot area. Default is 6. |
None
|
show_legend
|
bool
|
If True, include a legend. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/analysis.py
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 | |
uqdd.metrics.analysis.move_model_folders ¶
move_model_folders(df: DataFrame, search_dirs: List[str], output_dir: str, overwrite: bool = False) -> None
Move or merge model directories into a single output folder based on model names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame containing a 'model name' column. |
required |
search_dirs
|
list of str
|
Directories to search for model subfolders. |
required |
output_dir
|
str
|
Destination directory where model folders will be moved or merged. |
required |
overwrite
|
bool
|
If True, existing folders are merged (copied) with source. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/analysis.py
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 | |
uqdd.metrics.analysis.load_predictions ¶
load_predictions(model_path: str) -> pd.DataFrame
Load pickled predictions from a model directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_path
|
str
|
Path to the model directory containing 'preds.pkl'. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame loaded from the pickle file. |
Source code in uqdd/metrics/analysis.py
962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 | |
uqdd.metrics.analysis.calculate_rmse_rejection_curve ¶
calculate_rmse_rejection_curve(preds: DataFrame, uncertainty_col: str = 'y_alea', true_label_col: str = 'y_true', pred_label_col: str = 'y_pred', normalize_rmse: bool = False, random_rejection: bool = False, unc_type: Optional[str] = None, max_rejection_ratio: float = 0.95) -> Tuple[np.ndarray, np.ndarray, float]
Compute RMSE vs. rejection rate curve and its AUC by rejecting high-uncertainty predictions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preds
|
DataFrame
|
DataFrame with columns for true labels, predicted labels, and uncertainty components. |
required |
uncertainty_col
|
str
|
Column name for uncertainty to sort by if |
'y_alea'
|
true_label_col
|
str
|
Column name for true labels. Default is "y_true". |
'y_true'
|
pred_label_col
|
str
|
Column name for predicted labels. Default is "y_pred". |
'y_pred'
|
normalize_rmse
|
bool
|
If True, normalize RMSE by the initial RMSE before rejection. Default is False. |
False
|
random_rejection
|
bool
|
If True, randomly reject samples instead of sorting by uncertainty. Default is False. |
False
|
unc_type
|
(aleatoric, epistemic, both)
|
Which uncertainty to use. If "both", sums aleatoric and epistemic. If None, use |
"aleatoric"
|
max_rejection_ratio
|
float
|
Maximum fraction of samples to reject (exclusive of the tail). Default is 0.95. |
0.95
|
Returns:
| Type | Description |
|---|---|
(ndarray, ndarray, float)
|
Tuple of (rejection_rates, rmses, AUC of the RMSE–rejection curve). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in uqdd/metrics/analysis.py
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 | |
uqdd.metrics.analysis.calculate_rejection_curve ¶
calculate_rejection_curve(df: DataFrame, model_paths: List[str], unc_col: str, random_rejection: bool = False, normalize_rmse: bool = False, max_rejection_ratio: float = 0.95) -> Tuple[np.ndarray, np.ndarray, np.ndarray, float, float]
Aggregate RMSE–rejection curves across models and compute mean/std and AUC statistics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Auxiliary DataFrame (not used directly, kept for API symmetry). |
required |
model_paths
|
list of str
|
Paths to model directories containing 'preds.pkl'. |
required |
unc_col
|
str
|
Uncertainty column name to use when computing curves (e.g., 'y_alea' or 'y_eps'). |
required |
random_rejection
|
bool
|
If True, randomly reject samples. Default is False. |
False
|
normalize_rmse
|
bool
|
If True, normalize RMSE by the initial RMSE. Default is False. |
False
|
max_rejection_ratio
|
float
|
Maximum fraction of samples to reject. Default is 0.95. |
0.95
|
Returns:
| Type | Description |
|---|---|
(ndarray, ndarray, ndarray, float, float)
|
Tuple of (rejection_rates, mean_rmses, std_rmses, mean_auc, std_auc). |
Source code in uqdd/metrics/analysis.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 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 | |
uqdd.metrics.analysis.get_handles_labels ¶
get_handles_labels(ax: Axes, group_order: List[str]) -> Tuple[List, List[str]]
Extract legend handles/labels ordered by group prefix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Axes object from which to retrieve legend entries. |
required |
group_order
|
list of str
|
Group prefixes to order legend entries by. |
required |
Returns:
| Type | Description |
|---|---|
(list, list of str)
|
Ordered handles and labels. |
Source code in uqdd/metrics/analysis.py
1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 | |
uqdd.metrics.analysis.plot_rmse_rejection_curves ¶
plot_rmse_rejection_curves(df: DataFrame, base_dir: str, cmap: str = 'tab10_r', color_dict: Optional[Dict[str, str]] = None, save_dir_plot: Optional[str] = None, add_to_title: str = '', normalize_rmse: bool = False, unc_type: str = 'aleatoric', max_rejection_ratio: float = 0.95, group_order: Optional[List[str]] = None, fig_width: Optional[float] = None, fig_height: Optional[float] = None, show_legend: bool = False) -> pd.DataFrame
Plot RMSE–rejection curves per group, including random rejection baselines, and summarize AUCs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame containing columns 'Group', 'Split', and 'project_model'. |
required |
base_dir
|
str
|
Base directory where model paths are located. |
required |
cmap
|
str
|
Colormap name used to derive distinct colors per group. Default is "tab10_r". |
'tab10_r'
|
color_dict
|
dict[str, str] or None
|
Precomputed color mapping from group to color. If None, one is generated. |
None
|
save_dir_plot
|
str or None
|
Directory to save the plot images. Default is None. |
None
|
add_to_title
|
str
|
Suffix for the plot filename and title. Default is empty string. |
''
|
normalize_rmse
|
bool
|
If True, normalize RMSE by initial RMSE. Default is False. |
False
|
unc_type
|
(aleatoric, epistemic, both)
|
Uncertainty component to use for rejection. Default is "aleatoric". |
"aleatoric"
|
max_rejection_ratio
|
float
|
Maximum fraction of samples to reject. Default is 0.95. |
0.95
|
group_order
|
list of str or None
|
Order of groups in the legend. Default derives from data. |
None
|
fig_width
|
float or None
|
Plot width. Default is 6. |
None
|
fig_height
|
float or None
|
Plot height. Default is 6. |
None
|
show_legend
|
bool
|
If True, include a legend. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Summary DataFrame with columns ['Model type', 'Split', 'Group', 'AUC-RRC_mean', 'AUC-RRC_std']. |
Source code in uqdd/metrics/analysis.py
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 | |
uqdd.metrics.analysis.plot_auc_comparison ¶
plot_auc_comparison(stats_df: DataFrame, cmap: str = 'tab10_r', color_dict: Optional[Dict[str, str]] = None, save_dir: Optional[str] = None, add_to_title: str = '', min_y_axis: float = 0.0, hatches_dict: Optional[Dict[str, str]] = None, group_order: Optional[List[str]] = None, fig_width: Optional[float] = None, fig_height: Optional[float] = None, show_legend: bool = False) -> None
Plot bar charts comparing RRC-AUC across splits and model types, including random reject baselines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stats_df
|
DataFrame
|
Summary DataFrame with columns ['Group', 'Split', 'Model type', 'AUC-RRC_mean', 'AUC-RRC_std']. |
required |
cmap
|
str
|
Colormap name used to derive distinct colors per model type. Default is "tab10_r". |
'tab10_r'
|
color_dict
|
dict[str, str] or None
|
Precomputed color mapping from model type to color. If None, one is generated. |
None
|
save_dir
|
str or None
|
Directory to save plot images. Default is None. |
None
|
add_to_title
|
str
|
Title suffix for the plot. Default is empty string. |
''
|
min_y_axis
|
float
|
Minimum y-axis limit. Default is 0.0. |
0.0
|
hatches_dict
|
dict[str, str] or None
|
Hatch mapping for splits (e.g., {"stratified": "\"}). Default uses sensible defaults. |
None
|
group_order
|
list of str or None
|
Order of groups in the legend and x-axis. Default derives from data. |
None
|
fig_width
|
float or None
|
Plot width. Default is 6. |
None
|
fig_height
|
float or None
|
Plot height. Default is 6. |
None
|
show_legend
|
bool
|
If True, include a legend. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/analysis.py
1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 | |
uqdd.metrics.analysis.save_stats_df ¶
save_stats_df(stats_df: DataFrame, save_dir: str, add_to_title: str = '') -> None
Save a stats DataFrame to CSV in a given directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stats_df
|
DataFrame
|
DataFrame to save. |
required |
save_dir
|
str
|
Target directory to save the CSV. |
required |
add_to_title
|
str
|
Suffix to append to the filename. Default is empty string. |
''
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/analysis.py
1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 | |
uqdd.metrics.analysis.load_stats_df ¶
load_stats_df(save_dir: str, add_to_title: str = '') -> pd.DataFrame
Load a stats DataFrame from CSV in a given directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save_dir
|
str
|
Directory containing the CSV. |
required |
add_to_title
|
str
|
Suffix appended to the filename. Default is empty string. |
''
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Loaded DataFrame. |
Source code in uqdd/metrics/analysis.py
1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 | |
uqdd.metrics.constants ¶
uqdd.metrics.reassessment ¶
Model reassessment utilities: loading trained models, generating predictions, computing NLL, exporting artifacts, and recalibrating with isotonic regression.
This module wires together model loaders and predictors to re-run evaluation on saved runs, export standardized prediction pickles, append NLL to CSV logs, and apply isotonic recalibration using validation data.
uqdd.metrics.reassessment.nll_evidentials ¶
nll_evidentials(evidential_model, test_dataloader, model_type: str = 'evidential', num_mc_samples: int = 100, device=DEVICE)
Compute negative log-likelihood (NLL) for evidential-style models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
evidential_model
|
Module
|
Trained model instance. |
required |
test_dataloader
|
DataLoader
|
DataLoader providing test set batches. |
required |
model_type
|
(evidential, eoe, emc)
|
Model family determining the NLL backend. Default is "evidential". |
"evidential"
|
num_mc_samples
|
int
|
Number of MC samples for EMC models. Default is 100. |
100
|
device
|
device
|
Device to run evaluation on. Default uses |
DEVICE
|
Returns:
| Type | Description |
|---|---|
float or None
|
Scalar NLL if supported by the model type; None otherwise. |
Source code in uqdd/metrics/reassessment.py
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 | |
uqdd.metrics.reassessment.convert_to_list ¶
convert_to_list(val)
Parse a string representation of a Python list to a list; pass through non-strings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
val
|
str or any
|
Input value, possibly a string encoding of a list. |
required |
Returns:
| Type | Description |
|---|---|
list
|
Parsed list if |
any
|
Original value if not a string. |
Notes
- Uses
ast.literal_evalfor safe evaluation. - Prints a warning and returns [] when parsing fails.
Source code in uqdd/metrics/reassessment.py
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 | |
uqdd.metrics.reassessment.preprocess_runs ¶
preprocess_runs(runs_path: str, models_dir: str = MODELS_DIR, data_name: str = 'papyrus', activity_type: str = 'xc50', descriptor_protein: str = 'ankh-large', descriptor_chemical: str = 'ecfp2048', data_specific_path: str = 'papyrus/xc50/all', prot_input_dim: int = 1536, chem_input_dim: int = 2048) -> pd.DataFrame
Read a runs CSV and enrich with resolved model paths and descriptor metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runs_path
|
str
|
Path to the CSV file containing run metadata. |
required |
models_dir
|
str
|
Directory containing trained model .pt files. Default uses |
MODELS_DIR
|
data_name
|
str
|
Dataset identifier. Default is "papyrus". |
'papyrus'
|
activity_type
|
str
|
Activity type (e.g., "xc50", "kc"). Default is "xc50". |
'xc50'
|
descriptor_protein
|
str
|
Protein descriptor type. Default is "ankh-large". |
'ankh-large'
|
descriptor_chemical
|
str
|
Chemical descriptor type. Default is "ecfp2048". |
'ecfp2048'
|
data_specific_path
|
str
|
Subpath encoding dataset context for figures/exports. Default is "papyrus/xc50/all". |
'papyrus/xc50/all'
|
prot_input_dim
|
int
|
Protein input dimensionality. Default is 1536. |
1536
|
chem_input_dim
|
int
|
Chemical input dimensionality. Default is 2048. |
2048
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Preprocessed runs DataFrame with columns like 'model_name', 'model_path', and descriptor fields. |
Notes
- Resolves
model_nameto actual .pt files via glob and sets 'model_path'. - Adds multi-task flag 'MT' from 'n_targets' > 1.
- Converts layer columns from strings to lists using
convert_to_list.
Source code in uqdd/metrics/reassessment.py
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 | |
uqdd.metrics.reassessment.get_model_class ¶
get_model_class(model_type: str)
Map a model type name to the corresponding class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_type
|
str
|
Model type identifier (e.g., "pnn", "ensemble", "evidential", "eoe", "emc", "mcdropout"). |
required |
Returns:
| Type | Description |
|---|---|
type
|
Model class matching the type. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the |
Source code in uqdd/metrics/reassessment.py
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 | |
uqdd.metrics.reassessment.get_predict_fn ¶
get_predict_fn(model_type: str, num_mc_samples: int = 100)
Get the appropriate predict function and kwargs for a given model type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_type
|
str
|
Model type identifier. |
required |
num_mc_samples
|
int
|
Number of MC samples for MC Dropout or EMC models. Default is 100. |
100
|
Returns:
| Type | Description |
|---|---|
(callable, dict)
|
Tuple of (predict_function, keyword_arguments). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the |
Source code in uqdd/metrics/reassessment.py
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 | |
uqdd.metrics.reassessment.get_preds ¶
get_preds(model, dataloaders, model_type: str, subset: str = 'test', num_mc_samples: int = 100)
Run inference and unpack predictions for the requested subset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
Trained model instance. |
required |
dataloaders
|
dict
|
Dictionary of DataLoaders keyed by subset (e.g., 'train', 'val', 'test'). |
required |
model_type
|
str
|
Model type determining the predict function and outputs. |
required |
subset
|
str
|
Subset key to use from |
'test'
|
num_mc_samples
|
int
|
Number of MC samples for stochastic predictors. Default is 100. |
100
|
Returns:
| Type | Description |
|---|---|
tuple
|
(preds, labels, alea_vars, epi_vars) where |
Source code in uqdd/metrics/reassessment.py
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 | |
uqdd.metrics.reassessment.pkl_preds_export ¶
pkl_preds_export(preds, labels, alea_vars, epi_vars, outpath: str, model_type: str, logger=None)
Export predictions and uncertainties to a standardized pickle and return the DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preds
|
ndarray or Tensor
|
Model predictions. |
required |
labels
|
ndarray or Tensor
|
True labels. |
required |
alea_vars
|
ndarray or Tensor
|
Aleatoric uncertainty components. |
required |
epi_vars
|
ndarray or Tensor or None
|
Epistemic uncertainty components, or None for non-evidential models. |
required |
outpath
|
str
|
Output directory to write 'preds.pkl'. |
required |
model_type
|
str
|
Model type used to guide |
required |
logger
|
Logger or None
|
Logger for messages. Default is None. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with columns [y_true, y_pred, y_err, y_alea, y_eps]. |
Source code in uqdd/metrics/reassessment.py
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 | |
uqdd.metrics.reassessment.csv_nll_post_processing ¶
csv_nll_post_processing(csv_path: str) -> None
Normalize NLL values in a CSV by taking the first value per model name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
csv_path
|
str
|
Path to the CSV file containing a 'model name' and 'NLL' column. |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/reassessment.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
uqdd.metrics.reassessment.reassess_metrics ¶
reassess_metrics(runs_df: DataFrame, figs_out_path: str, csv_out_path: str, project_out_name: str, logger) -> None
Reassess metrics for each run: reload model, predict, compute NLL, evaluate, and recalibrate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runs_df
|
DataFrame
|
Preprocessed runs DataFrame with resolved 'model_path' and configuration fields. |
required |
figs_out_path
|
str
|
Directory where per-model figures and prediction pickles are saved. |
required |
csv_out_path
|
str
|
Path to a CSV for logging metrics (passed to |
required |
project_out_name
|
str
|
Name used for grouping results in downstream logging. |
required |
logger
|
Logger
|
Logger instance used through evaluation and recalibration. |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Notes
- Skips models already reassessed when a figure directory exists.
- Uses validation split for isotonic recalibration and logs final metrics.
Source code in uqdd/metrics/reassessment.py
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 | |
uqdd.metrics.stats ¶
Statistical utilities for metrics analysis and significance testing.
This module includes helpers to compute descriptive statistics, confidence intervals, bootstrap aggregates, correlation and significance tests, and summary tables to support model evaluation and reporting.
uqdd.metrics.stats.calc_regression_metrics ¶
calc_regression_metrics(df, cycle_col, val_col, pred_col, thresh)
Compute regression and thresholded classification metrics per cycle/method/split.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame containing true and predicted values. |
required |
cycle_col
|
str
|
Column name identifying cross-validation cycles. |
required |
val_col
|
str
|
Column with true target values. |
required |
pred_col
|
str
|
Column with predicted target values. |
required |
thresh
|
float
|
Threshold to derive binary classes for precision/recall. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Metrics per (cv_cycle, method, split) with columns ['mae', 'mse', 'r2', 'rho', 'prec', 'recall']. |
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.stats.bootstrap_ci ¶
bootstrap_ci(data, func=np.mean, n_bootstrap=1000, ci=95, random_state=42)
Compute bootstrap confidence interval for a statistic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
array - like
|
Sequence of numeric values. |
required |
func
|
callable
|
Statistic function applied to bootstrap samples (e.g., numpy.mean). Default is numpy.mean. |
mean
|
n_bootstrap
|
int
|
Number of bootstrap resamples. Default is 1000. |
1000
|
ci
|
int or float
|
Confidence level percentage (e.g., 95). Default is 95. |
95
|
random_state
|
int
|
Seed for reproducibility. Default is 42. |
42
|
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Lower and upper bounds for the confidence interval. |
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.stats.rm_tukey_hsd ¶
rm_tukey_hsd(df, metric, group_col, alpha=0.05, sort=False, direction_dict=None)
Repeated-measures Tukey HSD approximation using RM-ANOVA and studentized range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Long-form DataFrame with columns including the metric, group, and 'cv_cycle' subject. |
required |
metric
|
str
|
Metric column to compare. |
required |
group_col
|
str
|
Column indicating groups (e.g., method/model type). |
required |
alpha
|
float
|
Family-wise error rate for intervals. Default is 0.05. |
0.05
|
sort
|
bool
|
If True, sort groups by mean value of the metric. Default is False. |
False
|
direction_dict
|
dict or None
|
Mapping of metric -> 'maximize'|'minimize' to set sort ascending/descending. |
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
(result_tab, df_means, df_means_diff, p_values_matrix) where: - result_tab: DataFrame of pairwise comparisons with mean differences and CIs. - df_means: mean per group. - df_means_diff: matrix of mean differences. - pc: matrix of adjusted p-values. |
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.stats.make_boxplots ¶
make_boxplots(df, metric_ls, save_dir=None, name_prefix='', model_order=None)
Plot boxplots for each metric grouped by method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. |
required |
metric_ls
|
list of str
|
Metrics to visualize. |
required |
save_dir
|
str or None
|
Directory to save the plot. Default is None. |
None
|
name_prefix
|
str
|
Prefix for the output filename. Default is empty. |
''
|
model_order
|
list of str or None
|
Explicit order of methods on the x-axis. Default derives from data. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.stats.make_boxplots_parametric ¶
make_boxplots_parametric(df, metric_ls, save_dir=None, name_prefix='', model_order=None)
Plot boxplots with RM-ANOVA p-values annotated per metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. |
required |
metric_ls
|
list of str
|
Metrics to visualize. |
required |
save_dir
|
str or None
|
Directory to save the plot. Default is None. |
None
|
name_prefix
|
str
|
Prefix for the output filename. Default is empty. |
''
|
model_order
|
list of str or None
|
Explicit order of methods on the x-axis. Default derives from data. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.stats.make_boxplots_nonparametric ¶
make_boxplots_nonparametric(df, metric_ls, save_dir=None, name_prefix='', model_order=None)
Plot boxplots with Friedman p-values annotated per metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. |
required |
metric_ls
|
list of str
|
Metrics to visualize. |
required |
save_dir
|
str or None
|
Directory to save the plot. Default is None. |
None
|
name_prefix
|
str
|
Prefix for the output filename. Default is empty. |
''
|
model_order
|
list of str or None
|
Explicit order of methods on the x-axis. Default derives from data. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.stats.make_sign_plots_nonparametric ¶
make_sign_plots_nonparametric(df, metric_ls, save_dir=None, name_prefix='', model_order=None)
Plot significance heatmaps (Conover post-hoc) for nonparametric comparisons.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. |
required |
metric_ls
|
list of str
|
Metrics to analyze. |
required |
save_dir
|
str or None
|
Directory to save the plot. Default is None. |
None
|
name_prefix
|
str
|
Prefix for the output filename. Default is empty. |
''
|
model_order
|
list of str or None
|
Explicit order of methods on axes. Default derives from data. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.stats.make_critical_difference_diagrams ¶
make_critical_difference_diagrams(df, metric_ls, save_dir=None, name_prefix='', model_order=None)
Plot critical difference diagrams per metric using average ranks and post-hoc p-values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. |
required |
metric_ls
|
list of str
|
Metrics to analyze. |
required |
save_dir
|
str or None
|
Directory to save the plot. Default is None. |
None
|
name_prefix
|
str
|
Prefix for the output filename. Default is empty. |
''
|
model_order
|
list of str or None
|
Explicit order of models on diagrams. Default derives from data. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.stats.make_normality_diagnostic ¶
make_normality_diagnostic(df, metric_ls, save_dir=None, name_prefix='')
Plot normality diagnostics (histogram/KDE and Q-Q) for residualized metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. |
required |
metric_ls
|
list of str
|
Metrics to diagnose. |
required |
save_dir
|
str or None
|
Directory to save the plot. Default is None. |
None
|
name_prefix
|
str
|
Prefix for the output filename. Default is empty. |
''
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.stats.mcs_plot ¶
mcs_plot(pc, effect_size, means, labels=True, cmap=None, cbar_ax_bbox=None, ax=None, show_diff=True, cell_text_size=10, axis_text_size=8, show_cbar=True, reverse_cmap=False, vlim=None, **kwargs)
Render a multiple-comparisons significance heatmap annotated with effect sizes and stars.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pc
|
DataFrame
|
Matrix of adjusted p-values. |
required |
effect_size
|
DataFrame
|
Matrix of mean differences (effect sizes) aligned with |
required |
means
|
Series
|
Mean values per group for labeling. |
required |
labels
|
bool
|
If True, add x/y tick labels from |
True
|
cmap
|
str or None
|
Colormap name for effect sizes. Default is 'YlGnBu'. |
None
|
cbar_ax_bbox
|
tuple or None
|
Custom colorbar axes bbox; unused here but kept for API compatibility. |
None
|
ax
|
Axes or None
|
Axes to draw into; if None, a new axes is created. |
None
|
show_diff
|
bool
|
If True, annotate cells with rounded effect sizes plus significance. Default is True. |
True
|
cell_text_size
|
int
|
Font size for annotations. Default is 10. |
10
|
axis_text_size
|
int
|
Font size for axis tick labels. Default is 8. |
8
|
show_cbar
|
bool
|
If True, show colorbar. Default is True. |
True
|
reverse_cmap
|
bool
|
If True, use reversed colormap. Default is False. |
False
|
vlim
|
float or None
|
Symmetric limit for color scaling around 0. Default is None. |
None
|
Returns:
| Type | Description |
|---|---|
Axes
|
Axes containing the rendered heatmap. |
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.stats.make_mcs_plot_grid ¶
make_mcs_plot_grid(df, stats_list, group_col, alpha=0.05, figsize=(20, 10), direction_dict=None, effect_dict=None, show_diff=True, cell_text_size=16, axis_text_size=12, title_text_size=16, sort_axes=False, save_dir=None, name_prefix='', model_order=None)
Generate a grid of MCS plots for multiple metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. |
required |
stats_list
|
list of str
|
Metrics to include. |
required |
group_col
|
str
|
Column indicating groups (e.g., method). |
required |
alpha
|
float
|
Significance level. Default is 0.05. |
0.05
|
figsize
|
tuple
|
Figure size. Default is (20, 10). |
(20, 10)
|
direction_dict
|
dict or None
|
Mapping metric -> 'maximize'|'minimize' for colormap orientation. |
None
|
effect_dict
|
dict or None
|
Mapping metric -> effect size limit for color scaling. |
None
|
show_diff
|
bool
|
If True, annotate mean differences; else annotate significance only. |
True
|
cell_text_size
|
int
|
Annotation font size. |
16
|
axis_text_size
|
int
|
Axis label font size. |
12
|
title_text_size
|
int
|
Title font size. |
16
|
sort_axes
|
bool
|
If True, sort groups by mean values per metric. |
False
|
save_dir
|
str or None
|
Directory to save the plot. Default is None. |
None
|
name_prefix
|
str
|
Filename prefix. Default is empty. |
''
|
model_order
|
list of str or None
|
Explicit model order for rows/cols. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.stats.make_scatterplot ¶
make_scatterplot(df, val_col, pred_col, thresh, cycle_col='cv_cycle', group_col='method', save_dir=None)
Scatter plots of predicted vs true values per method, with threshold lines and summary stats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. |
required |
val_col
|
str
|
True value column. |
required |
pred_col
|
str
|
Predicted value column. |
required |
thresh
|
float
|
Threshold for classification overlays. |
required |
cycle_col
|
str
|
Cross-validation cycle column. Default is 'cv_cycle'. |
'cv_cycle'
|
group_col
|
str
|
Method/model type column. Default is 'method'. |
'method'
|
save_dir
|
str or None
|
Directory to save the plot. Default is None. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.stats.ci_plot ¶
ci_plot(result_tab, ax_in, name)
Plot mean differences with confidence intervals for pairwise comparisons.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result_tab
|
DataFrame
|
Output of rm_tukey_hsd with columns ['meandiff', 'lower', 'upper']. |
required |
ax_in
|
Axes
|
Axes to plot into. |
required |
name
|
str
|
Title for the plot. |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.stats.make_ci_plot_grid ¶
make_ci_plot_grid(df_in, metric_list, group_col='method', save_dir=None, name_prefix='', model_order=None)
Plot a grid of confidence-interval charts for multiple metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_in
|
DataFrame
|
Input DataFrame. |
required |
metric_list
|
list of str
|
Metrics to render. |
required |
group_col
|
str
|
Group column (e.g., 'method'). Default is 'method'. |
'method'
|
save_dir
|
str or None
|
Directory to save the plot. Default is None. |
None
|
name_prefix
|
str
|
Filename prefix. Default is empty. |
''
|
model_order
|
list of str or None
|
Explicit row order for the CI plots. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.stats.recall_at_precision ¶
recall_at_precision(y_true, y_score, precision_threshold=0.5, direction='greater')
Find recall and threshold achieving at least a target precision.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
array - like
|
Binary ground-truth labels. |
required |
y_score
|
array - like
|
Continuous scores or probabilities. |
required |
precision_threshold
|
float
|
Minimum precision to achieve. Default is 0.5. |
0.5
|
direction
|
(greater, lesser)
|
If 'greater', thresholding uses >=; if 'lesser', uses <=. Default is 'greater'. |
"greater"
|
Returns:
| Type | Description |
|---|---|
tuple[float, float or None]
|
(recall, threshold) if achievable; otherwise (nan, None). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.stats.calc_classification_metrics ¶
calc_classification_metrics(df_in, cycle_col, val_col, prob_col, pred_col)
Compute classification metrics per cycle/method/split, including ROC-AUC, PR-AUC, MCC, recall, and TNR.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_in
|
DataFrame
|
Input DataFrame. |
required |
cycle_col
|
str
|
Column name for cross-validation cycles. |
required |
val_col
|
str
|
True binary label column. |
required |
prob_col
|
str
|
Predicted probability/score column. |
required |
pred_col
|
str
|
Predicted binary label column. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Metrics per (cv_cycle, method, split) with columns ['roc_auc', 'pr_auc', 'mcc', 'recall', 'tnr']. |
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.stats.make_curve_plots ¶
make_curve_plots(df)
Plot ROC and PR curves for split/method selections with threshold markers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame containing 'cv_cycle', 'split', and method columns plus true/probability fields. |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.stats.harmonize_columns ¶
harmonize_columns(df)
Normalize common column names to ['method', 'split', 'cv_cycle'].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame with possibly varied column naming. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with standardized column names and assertion that required columns exist. |
Source code in uqdd/metrics/stats.py
872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 | |
uqdd.metrics.stats.cliffs_delta ¶
cliffs_delta(x, y)
Compute Cliff's delta effect size and qualitative interpretation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array - like
|
First sample of numeric values. |
required |
y
|
array - like
|
Second sample of numeric values. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, str]
|
(delta, interpretation) where interpretation is one of {'negligible','small','medium','large'}. |
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.stats.wilcoxon_pairwise_test ¶
wilcoxon_pairwise_test(df, metric, model_a, model_b, task=None, split=None, seed_col=None)
Perform paired Wilcoxon signed-rank test between two models on a metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. |
required |
metric
|
str
|
Metric column to compare. |
required |
model_a
|
str
|
First model type name. |
required |
model_b
|
str
|
Second model type name. |
required |
task
|
str or None
|
Task filter. Default is None. |
None
|
split
|
str or None
|
Split filter. Default is None. |
None
|
seed_col
|
str or None
|
Optional seed column identifier (unused here). |
None
|
Returns:
| Type | Description |
|---|---|
dict or None
|
Test summary including statistic, p-value, Cliff's delta, CI on differences; None if insufficient data. |
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.stats.holm_bonferroni_correction ¶
holm_bonferroni_correction(p_values)
Apply Holm–Bonferroni correction to an array of p-values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p_values
|
array - like
|
Raw p-values. |
required |
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray]
|
(corrected_p_values, rejected_mask) where rejected indicates significance after correction. |
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.stats.pairwise_model_comparison ¶
pairwise_model_comparison(df, metrics, models=None, tasks=None, splits=None, alpha=0.05)
Run pairwise Wilcoxon tests across models/tasks/splits for multiple metrics and adjust p-values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. |
required |
metrics
|
list of str
|
Metrics to compare. |
required |
models
|
list of str or None
|
Models to include; default derives from data. |
None
|
tasks
|
list of str or None
|
Tasks to include; default derives from data. |
None
|
splits
|
list of str or None
|
Splits to include; default derives from data. |
None
|
alpha
|
float
|
Significance level. Default is 0.05. |
0.05
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Results table with corrected p-values and significance flags. |
Source code in uqdd/metrics/stats.py
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 | |
uqdd.metrics.stats.friedman_nemenyi_test ¶
friedman_nemenyi_test(df, metrics, models=None, alpha=0.05)
Run Friedman test across models with Nemenyi post-hoc where significant, per metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. |
required |
metrics
|
list of str
|
Metrics to test. |
required |
models
|
list of str or None
|
Models to include; default derives from data. |
None
|
alpha
|
float
|
Significance level. Default is 0.05. |
0.05
|
Returns:
| Type | Description |
|---|---|
dict
|
Mapping metric -> result dict containing stats, p-values, mean ranks, and optional post-hoc outputs. |
Source code in uqdd/metrics/stats.py
1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 | |
uqdd.metrics.stats.calculate_critical_difference ¶
calculate_critical_difference(k, n, alpha=0.05)
Compute the critical difference for average ranks in Nemenyi post-hoc tests.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
int
|
Number of models. |
required |
n
|
int
|
Number of datasets/blocks. |
required |
alpha
|
float
|
Significance level. Default is 0.05. |
0.05
|
Returns:
| Type | Description |
|---|---|
float
|
Critical difference value. |
Source code in uqdd/metrics/stats.py
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 | |
uqdd.metrics.stats.bootstrap_auc_difference ¶
bootstrap_auc_difference(auc_values_a, auc_values_b, n_bootstrap=1000, ci=95, random_state=42)
Bootstrap confidence interval for difference of mean AUCs between two models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
auc_values_a
|
array - like
|
AUC values for model A. |
required |
auc_values_b
|
array - like
|
AUC values for model B. |
required |
n_bootstrap
|
int
|
Number of bootstrap resamples. Default is 1000. |
1000
|
ci
|
int or float
|
Confidence level in percent. Default is 95. |
95
|
random_state
|
int
|
Seed for reproducibility. Default is 42. |
42
|
Returns:
| Type | Description |
|---|---|
dict
|
{'mean_difference', 'ci_lower', 'ci_upper', 'bootstrap_differences'} |
Source code in uqdd/metrics/stats.py
1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 | |
uqdd.metrics.stats.plot_critical_difference_diagram ¶
plot_critical_difference_diagram(friedman_results, metric, save_dir=None, alpha=0.05)
Plot a simple critical difference diagram using mean ranks and CD value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
friedman_results
|
dict
|
Output dictionary from friedman_nemenyi_test. |
required |
metric
|
str
|
Metric to plot. |
required |
save_dir
|
str or None
|
Directory to save the plot. Default is None. |
None
|
alpha
|
float
|
Significance level used to compute CD. Default is 0.05. |
0.05
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/stats.py
1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 | |
uqdd.metrics.stats.analyze_significance ¶
analyze_significance(df_raw, metrics, direction_dict, effect_dict, save_dir=None, model_order=None, activity=None)
End-to-end significance analysis and plotting across splits for multiple metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_raw
|
DataFrame
|
Raw results DataFrame. |
required |
metrics
|
list of str
|
Metric names to analyze. |
required |
direction_dict
|
dict
|
Mapping metric -> 'maximize'|'minimize'. |
required |
effect_dict
|
dict
|
Mapping metric -> effect size threshold for visualization. |
required |
save_dir
|
str or None
|
Directory to save plots and outputs. Default is None. |
None
|
model_order
|
list of str or None
|
Explicit ordering of models. Default derives from data. |
None
|
activity
|
str or None
|
Activity name for prefixes. Default is None. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in uqdd/metrics/stats.py
1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 | |
uqdd.metrics.stats.comprehensive_statistical_analysis ¶
comprehensive_statistical_analysis(df, metrics, models=None, tasks=None, splits=None, save_dir=None, alpha=0.05)
Run a comprehensive suite of statistical tests and export results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. |
required |
metrics
|
list of str
|
Metrics to analyze. |
required |
models
|
list of str or None
|
Models to include. Default derives from data. |
None
|
tasks
|
list of str or None
|
Tasks to include. Default derives from data. |
None
|
splits
|
list of str or None
|
Splits to include. Default derives from data. |
None
|
save_dir
|
str or None
|
Directory to save tables and JSON outputs. Default is None. |
None
|
alpha
|
float
|
Significance level. Default is 0.05. |
0.05
|
Returns:
| Type | Description |
|---|---|
dict
|
Results dict including pairwise tests, Friedman/Nemenyi outputs, and optional AUC bootstrap comparisons. |
Source code in uqdd/metrics/stats.py
1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 | |
uqdd.metrics.stats.generate_statistical_report ¶
generate_statistical_report(results, save_dir=None, df_raw=None, metrics=None, direction_dict=None, effect_dict=None)
Generate a human-readable text report from comprehensive statistical results and optionally run plots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
dict
|
Output of comprehensive_statistical_analysis. |
required |
save_dir
|
str or None
|
Directory to save the report text file. Default is None. |
None
|
df_raw
|
DataFrame or None
|
Raw DataFrame to run plotting-based significance analysis. Default is None. |
None
|
metrics
|
list of str or None
|
Metrics to plot (when df_raw provided). |
None
|
direction_dict
|
dict or None
|
Direction mapping for metrics (required when df_raw provided). |
None
|
effect_dict
|
dict or None
|
Effect threshold mapping (required when df_raw provided). |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Report text. |
Source code in uqdd/metrics/stats.py
1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 | |