Pipeline
pipeline
Main entry point module for the medpipe machine learning package.
Provides unified, high-level interfaces (MedpipeClassifier for binary
classification outcomes, MedpipeRegressor for regression outcomes)
orchestrating data preparation, model fitting, inference, and TRIPOD+AI
compliant evaluation.
MedpipeClassifier
User entry point and high-level pipeline runner for MedpipeClassifier.
Coordinates the complete machine learning lifecycle, delegating data ingress
and preprocessing setup to MedpipeOrchestrator, model cross-validation
and fitting to MedpipeClassifierRunner, and prediction and TRIPOD+AI evaluation to
MedpipeClassifierEvaluator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
str, Path, or MedpipeClassifierConfig
|
Path to the TOML configuration file or an instantiated MedpipeClassifierConfig object. |
required |
base_artifact_dir
|
str or Path
|
Root directory where versioned execution run artifacts, logs, and models are stored. |
"artifacts"
|
verbose_override
|
Union[bool, int, str, None]
|
Console verbosity setting configuration override. |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
mp_config |
MedpipeClassifierConfig
|
Validated configuration driving the pipeline. |
displayer |
MedpipeClassifierDisplayer
|
Visualisation engine rendering and persisting evaluation figures. |
Source code in medpipe/pipeline/pipeline.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 | |
models
property
Return the fitted models.
Returns:
| Name | Type | Description |
|---|---|---|
fitted_models |
Dict[str, Union[Pipeline, CalibratedClassifierCV]]
|
Fitted models from the MedpipeClassifierRunner object. |
is_fitted
property
Checks if the MedpipeClassifier is fitted by looking at MedpipeClassifierRunner.
Returns:
| Name | Type | Description |
|---|---|---|
fitted |
bool
|
True if the models have been fitted, False otherwise. |
run_dir
property
Returns the run_dir from the MedpipeOrchestrator object.
Returns:
| Name | Type | Description |
|---|---|---|
run_dir |
Path
|
Path to the run_dir. |
data_split
property
data_split: DataSplits
Access any of the data splits.
Return
DataSplits Any of the DataSplits attributes.
fairness_split
property
fairness_split: FairnessSplits | None
Access fairness stratification columns aligned with each data split.
Lets fairness analyses be run directly against the relevant columns (e.g. `pipeline.fairness_split.test["HOSPITAL"]") without re-extracting them from the raw dataset, and independently of whether those columns are also model predictors.
Return
FairnessSplits or None
Any of the FairnessSplits attributes, or None if no
workflow.evaluation.fairness configuration is set.
prepare_data
property
Access the orchestrator's data preparation function.
Ingests the configured dataset and creates the train/recal/test
splits, e.g. X_train, y_train, X_recal, y_recal, X_test, y_test,
groups_train = pipeline.prepare_data(). Keyword arguments are passed
to the underlying Pandas reader function.
Returns:
| Type | Description |
|---|---|
Callable
|
The bound |
metrics
property
Returns metrics used during evaluation.
Returns:
| Name | Type | Description |
|---|---|---|
metrics |
list[str]
|
List of metrics used during evaluation. |
fit
fit(
X_train: DataFrame,
y_train: DataFrame,
X_recal: DataFrame | None = None,
y_recal: DataFrame | None = None,
groups_train: ndarray | None = None,
) -> dict[str, Any]
Fit machine learning models across configured target outcomes via MedpipeClassifierRunner.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X_train
|
DataFrame
|
Training feature dataset. |
required |
y_train
|
DataFrame
|
Training outcome target labels (can contain multiple outcome columns). |
required |
X_recal
|
DataFrame
|
Recalibration feature dataset for post-hoc model calibration, default=None. |
None
|
y_recal
|
DataFrame
|
Recalibration outcome target labels, default=None. |
None
|
groups_train
|
ndarray
|
Group identifier array for group-based cross-validation splits, default=None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
fitted_models |
dict of str to object
|
Dictionary mapping outcome target names to their finalized fitted models. |
Source code in medpipe/pipeline/pipeline.py
predict
Predict class labels for input samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame or ndarray
|
Features dataset of shape (n_samples, n_features). |
required |
model
|
object
|
Fitted model instance. If None, resolved via |
None
|
outcome
|
str
|
Outcome name corresponding to an entry in |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
y_pred |
ndarray
|
Predicted class labels of shape (n_samples,). |
Source code in medpipe/pipeline/pipeline.py
predict_proba
predict_proba(
X: DataFrame | NDArray,
model: Any | None = None,
outcome: str | None = None,
) -> NDArray
Predict class probabilities for input samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame or ndarray
|
Features dataset of shape (n_samples, n_features). |
required |
model
|
object
|
Fitted model instance. If None, resolved via |
None
|
outcome
|
str
|
Outcome name corresponding to an entry in |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
y_proba |
ndarray
|
Predicted class probabilities of shape (n_samples, n_classes) or (n_samples,). |
Source code in medpipe/pipeline/pipeline.py
decision_function
decision_function(
X: DataFrame | NDArray,
model: Any | None = None,
outcome: str | None = None,
) -> NDArray
Compute decision function confidence scores for input samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame or ndarray
|
Features dataset of shape (n_samples, n_features). |
required |
model
|
object
|
Fitted model instance. If None, resolved via |
None
|
outcome
|
str
|
Outcome name corresponding to an entry in |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
scores |
ndarray
|
Confidence scores or decision function values of shape (n_samples,). |
Source code in medpipe/pipeline/pipeline.py
evaluate
evaluate(
X: DataFrame,
y: Series | NDArray,
outcome: str | None = None,
model: Any | None = None,
metrics: list[str] | None = None,
subgroup_specs: dict[
str, str | Callable[[DataFrame], Series]
]
| None = None,
fairness_data: DataFrame | None = None,
save_artifacts: bool = True,
) -> dict[str, Any]
Evaluate model performance with confidence intervals on full datasets and subgroups.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame
|
Feature dataset of shape (n_samples, n_features). |
required |
y
|
Series or ndarray
|
Ground truth target values of shape (n_samples,). |
required |
outcome
|
str
|
Outcome key name. Used for logging, model resolution, and artifact saving. |
None
|
model
|
object
|
Explicit fitted model instance. If None, resolved from
|
None
|
metrics
|
list of str
|
List of metrics to evaluate. If None, defaults to
|
None
|
subgroup_specs
|
dict of str to (str or callable)
|
Specifications for extracting demographic or clinical subgroups. |
None
|
fairness_data
|
DataFrame
|
Fairness stratification columns aligned with |
None
|
save_artifacts
|
bool
|
Whether to write evaluation summary results to disk via
|
True
|
Returns:
| Name | Type | Description |
|---|---|---|
results |
dict of str to Any
|
Nested dictionary containing outcome identifier, overall slice metrics, and subgroup performance. |
Source code in medpipe/pipeline/pipeline.py
run
Execute full end-to-end pipeline (data preparation, model fitting, and test evaluation).
Automates data ingestion, split creation, model cross-validation and fitting, and test evaluation with TRIPOD+AI reporting across all target outcomes. The model fitting duration and total run duration are recorded at the debug log level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
groups_train
|
ndarray
|
Group labels for training samples if group-based cross-validation is configured. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
pipeline_results |
dict of str to Any
|
Dictionary containing:
- |
Source code in medpipe/pipeline/pipeline.py
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 | |
plot_all
plot_all(
y_true: ndarray,
probas: ndarray,
outcome: str = "default",
n_bootstraps: int | None = None,
save: bool | None = None,
show: bool | None = None,
**style_kwargs: Any,
) -> dict[str, tuple[Figure | SubFigure, Axes]]
Execute all core evaluation visualization routines for a given outcome.
Generates and optionally persists the ROC curve, Precision-Recall curve, Data Distribution histogram, Reliability Diagram, and Decision Curve Analysis (DCA).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
ndarray
|
Ground truth binary target labels of shape (n_samples,). |
required |
probas
|
ndarray
|
Predicted probabilities of shape (n_samples, 2) or (n_samples,). |
required |
outcome
|
str
|
Outcome identifier used for figure titles and directory structuring. |
"default"
|
n_bootstraps
|
int
|
Number of bootstrap iterations for confidence interval estimation on ROC, PR, and reliability curves. If None, resolved from the display configuration. |
None
|
save
|
bool
|
Automatically save all generated plot artifacts to the run directory. If None, resolved from the display configuration. |
None
|
show
|
bool
|
Whether to display figures interactively before closing. If None, resolved from the display configuration. |
None
|
**style_kwargs
|
Any
|
Additional style parameters forwarded to underlying drawing primitives. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
plots |
dict of str to tuple of (matplotlib.figure.Figure, matplotlib.axes.Axes)
|
Dictionary mapping plot keys ('roc', 'pr', 'distribution', 'reliability', 'dca') to their rendered (Figure, Axes) Matplotlib objects. |
Source code in medpipe/pipeline/pipeline.py
load
classmethod
load(run_dir: str | Path) -> MedpipeClassifier
Reconstruct a MedpipeClassifier instance from a run artifact directory.
Parses the saved JSON configuration and restores serialized outcome model artifacts into the runner and evaluator engines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_dir
|
str or Path
|
Directory path of a previously executed MedpipeClassifier run artifact. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
pipe |
MedpipeClassifier
|
Re-instantiated MedpipeClassifier object ready for inference, evaluation, or visualization. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the resolved configuration JSON file is missing from the run directory. |
Source code in medpipe/pipeline/pipeline.py
MedpipeRegressor
User entry point and high-level pipeline runner for MedpipeRegressor.
Coordinates the complete machine learning lifecycle for regression
outcomes, delegating data ingress and preprocessing setup to
MedpipeOrchestrator, model cross-validation and fitting to
MedpipeRegressorRunner, and prediction and TRIPOD+AI evaluation to
MedpipeRegressorEvaluator.
Unlike MedpipeClassifier, there is no post-hoc recalibration step (not
a meaningful concept for regression outcomes). Distributional diagnostic
figures (coverage, sharpness, Winkler score, marginal calibration, PIT
histogram, and target-value data distribution) are available via
plot_all, which run() calls in the "audit" and "eval" run modes. The
figures are only available for models producing a predictive CDF through
predict_dist (currently OrdBoost only); run() skips them with a
warning for any other model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
str, Path, or MedpipeRegressorConfig
|
Path to a TOML configuration file (parsed by |
required |
base_artifact_dir
|
str or Path
|
Root directory where versioned execution run artifacts, logs, and models are stored. |
"artifacts"
|
verbose_override
|
Union[bool, int, str, None]
|
Console verbosity setting configuration override. |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
mp_config |
MedpipeRegressorConfig
|
Validated configuration driving the pipeline. |
displayer |
MedpipeRegressorDisplayer
|
Visualisation engine rendering and persisting distributional diagnostic figures. |
Source code in medpipe/pipeline/pipeline.py
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 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 1137 1138 1139 1140 1141 1142 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 | |
models
property
models: dict[str, DistributionalPipeline]
Return the fitted models.
Returns:
| Name | Type | Description |
|---|---|---|
fitted_models |
Dict[str, DistributionalPipeline]
|
Fitted models from the MedpipeRegressorRunner object. |
is_fitted
property
Checks if the MedpipeRegressor is fitted by looking at MedpipeRegressorRunner.
Returns:
| Name | Type | Description |
|---|---|---|
fitted |
bool
|
True if the models have been fitted, False otherwise. |
run_dir
property
Returns the run_dir from the MedpipeOrchestrator object.
Returns:
| Name | Type | Description |
|---|---|---|
run_dir |
Path
|
Path to the run_dir. |
data_split
property
data_split: DataSplits
Access any of the data splits.
Return
DataSplits Any of the DataSplits attributes.
fairness_split
property
fairness_split: FairnessSplits | None
Access fairness stratification columns aligned with each data split.
Lets fairness analyses be run directly against the relevant columns (e.g. `pipeline.fairness_split.test["HOSPITAL"]") without re-extracting them from the raw dataset, and independently of whether those columns are also model predictors.
Return
FairnessSplits or None
Any of the FairnessSplits attributes, or None if no
workflow.evaluation.fairness configuration is set.
prepare_data
property
Access the orchestrator's data preparation function.
Ingests the configured dataset and creates the train/recal/test
splits, e.g. X_train, y_train, X_recal, y_recal, X_test, y_test,
groups_train = pipeline.prepare_data(). Keyword arguments are passed
to the underlying Pandas reader function.
Returns:
| Type | Description |
|---|---|
Callable
|
The bound |
metrics
property
Returns metrics used during evaluation.
Returns:
| Name | Type | Description |
|---|---|---|
metrics |
list[str]
|
List of metrics used during evaluation. |
fit
fit(
X_train: DataFrame,
y_train: DataFrame,
X_recal: DataFrame | None = None,
y_recal: DataFrame | None = None,
groups_train: ndarray | None = None,
) -> dict[str, Any]
Fit machine learning models across configured target outcomes via MedpipeRegressorRunner.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X_train
|
DataFrame
|
Training feature dataset. |
required |
y_train
|
DataFrame
|
Training outcome target labels (can contain multiple outcome columns). |
required |
X_recal
|
DataFrame
|
Unused (no recalibration step for regression); accepted for
interface symmetry with |
None
|
y_recal
|
DataFrame
|
Unused (no recalibration step for regression); accepted for
interface symmetry with |
None
|
groups_train
|
ndarray
|
Group identifier array for group-based cross-validation splits, default=None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
fitted_models |
dict of str to object
|
Dictionary mapping outcome target names to their finalized fitted models. |
Source code in medpipe/pipeline/pipeline.py
predict
Predict continuous values for input samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame or ndarray
|
Features dataset of shape (n_samples, n_features). |
required |
model
|
object
|
Fitted model instance. If None, resolved via |
None
|
outcome
|
str
|
Outcome name corresponding to an entry in |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
y_pred |
ndarray
|
Predicted continuous values of shape (n_samples,). |
Source code in medpipe/pipeline/pipeline.py
predict_dist
predict_dist(
X: DataFrame | NDArray,
model: Any | None = None,
outcome: str | None = None,
) -> Any
Predict the full predictive distribution for input samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame or ndarray
|
Features dataset of shape (n_samples, n_features). |
required |
model
|
object
|
Fitted model instance. If None, resolved via |
None
|
outcome
|
str
|
Outcome name corresponding to an entry in |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The distribution object returned by the resolved model's
|
Source code in medpipe/pipeline/pipeline.py
evaluate
evaluate(
X: DataFrame,
y: Series | NDArray,
outcome: str | None = None,
model: Any | None = None,
metrics: list[str] | None = None,
subgroup_specs: dict[
str, str | Callable[[DataFrame], Series]
]
| None = None,
fairness_data: DataFrame | None = None,
save_artifacts: bool = True,
) -> dict[str, Any]
Evaluate model performance with confidence intervals on full datasets and subgroups.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame
|
Feature dataset of shape (n_samples, n_features). |
required |
y
|
Series or ndarray
|
Ground truth target values of shape (n_samples,). |
required |
outcome
|
str
|
Outcome key name. Used for logging, model resolution, and artifact saving. |
None
|
model
|
object
|
Explicit fitted model instance. If None, resolved from
|
None
|
metrics
|
list of str
|
List of metrics to evaluate. If None, defaults to
|
None
|
subgroup_specs
|
dict of str to (str or callable)
|
Specifications for extracting demographic or clinical subgroups. |
None
|
fairness_data
|
DataFrame
|
Fairness stratification columns aligned with |
None
|
save_artifacts
|
bool
|
Whether to write evaluation summary results to disk via
|
True
|
Returns:
| Name | Type | Description |
|---|---|---|
results |
dict of str to Any
|
Nested dictionary containing outcome identifier, overall slice metrics, and subgroup performance. |
Source code in medpipe/pipeline/pipeline.py
run
Execute full end-to-end pipeline (data preparation, model fitting, and test evaluation).
Automates data ingestion, split creation, model cross-validation and fitting, and test evaluation with TRIPOD+AI reporting across all target outcomes. The model fitting duration and total run duration are recorded at the debug log level.
Note: only models that support predict_dist, are able to generate plots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
groups_train
|
ndarray
|
Group labels for training samples if group-based cross-validation is configured. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
pipeline_results |
dict of str to Any
|
Dictionary containing:
- |
Source code in medpipe/pipeline/pipeline.py
970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 | |
plot_all
plot_all(
y_true: NDArray,
dist: ContinuousPredictiveDistribution,
outcome: str = "default",
coverage_levels: NDArray | None = None,
n_bootstraps: int | None = None,
save: bool | None = None,
show: bool | None = None,
**style_kwargs: Any,
) -> dict[str, tuple[Figure | SubFigure, Axes]]
Execute all core distributional diagnostic visualization routines for a given outcome.
Generates and optionally persists the coverage reliability curve,
sharpness curve, Winkler score curve, marginal calibration curve,
PIT histogram, and target-value data distribution histogram. Only
supported for models that produce a predictive CDF via
predict_dist (currently OrdBoost only). The
bin mapper required for the PIT histogram is extracted directly
from self.models[outcome]["regressor"].mapper_, so outcome must
match an entry in runner.fitted_models for the PIT histogram to
render; it stays skipped-with-a-clear-error otherwise, same as
when no mapper is available.
Called by run() in the "audit" and "eval" run modes for the outcomes
whose model is distribution-capable (e.g. OrdBoostRegressor).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
ndarray
|
Ground truth continuous target values of shape (n_samples,). |
required |
dist
|
ContinuousPredictiveDistribution
|
Predictive distribution for the same samples, e.g. from
|
required |
outcome
|
str
|
Outcome identifier used for figure titles, output folder
structuring, and to resolve the fitted model (and its bin
mapper) from |
"default"
|
coverage_levels
|
ndarray
|
Nominal central-interval coverage levels in percent, used for the
coverage, sharpness, and Winkler score curves. Defaults to
|
None
|
n_bootstraps
|
int
|
Number of bootstrap iterations for coverage, sharpness, and Winkler score curves. If None, resolved from the display configuration. |
None
|
save
|
bool
|
Automatically save all generated plot artifacts to the run directory. If None, resolved from the display configuration. |
None
|
show
|
bool
|
Whether to display figures interactively before closing. If None, resolved from the display configuration. |
None
|
**style_kwargs
|
Any
|
Additional style parameters forwarded to underlying drawing primitives. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
plots |
dict of str to tuple of (matplotlib.figure.Figure, matplotlib.axes.Axes)
|
Dictionary mapping plot keys ('coverage', 'sharpness', 'winkler', 'marginal_calibration', 'pit_histogram', 'data_distribution') to their rendered (Figure, Axes) Matplotlib objects. |
Source code in medpipe/pipeline/pipeline.py
1141 1142 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 | |
load
classmethod
load(run_dir: str | Path) -> MedpipeRegressor
Reconstruct a MedpipeRegressor instance from a run artifact directory.
Parses the saved JSON configuration and restores serialized outcome model artifacts into the runner and evaluator engines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_dir
|
str or Path
|
Directory path of a previously executed MedpipeRegressor run artifact. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
pipe |
MedpipeRegressor
|
Re-instantiated MedpipeRegressor object ready for inference, evaluation, or visualization. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the resolved configuration JSON file is missing from the run directory. |
Source code in medpipe/pipeline/pipeline.py
orchestrator
DataSplits
dataclass
Container holding prepared feature and target splits.
Attributes:
| Name | Type | Description |
|---|---|---|
X_train |
DataFrame
|
Samples used for training. |
y_train |
DataFrame
|
Training labels. |
X_recal |
DataFrame | None
|
Samples used for recalibration, if available. |
y_recal |
DataFrame | None
|
Recalibration labels, if available. |
X_test |
DataFrame
|
Samples used for testing. |
y_test |
DataFrame
|
Testing labels. |
groups_train |
NDArray
|
Groups used for splitting the training set, if available. |
Source code in medpipe/pipeline/orchestrator.py
FairnessSplits
dataclass
Container holding fairness stratification columns aligned with each prepared data split.
Populated whenever workflow.evaluation.fairness.strata is configured.
Holds every fairness stratum column exactly as ingested, independent of
whether a given column is also a model predictor, so fairness columns
(e.g. a "HOSPITAL" column used only for a spatial comparison) are always
available here without ever being merged into DataSplits' feature
frames.
Attributes:
| Name | Type | Description |
|---|---|---|
train |
DataFrame
|
Fairness stratum columns for the rows in |
test |
DataFrame
|
Fairness stratum columns for the rows in |
recal |
DataFrame | None
|
Fairness stratum columns for the rows in |
Source code in medpipe/pipeline/orchestrator.py
MedpipeOrchestrator
Handles data ingress, transformation preparation, and reproducibility management.
This orchestrator acts as the primary entry point for setting up the machine learning pipeline. It establishes the reproducibility environment, configures logging, ingests raw data, builds the scikit-learn preprocessing pipeline, and resolves configuration overrides and data splits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Union[str, Path, MedpipeClassifierConfig, MedpipeRegressorConfig]
|
Path to a TOML configuration file, or an already-instantiated
|
required |
base_artifact_dir
|
Union[str, Path]
|
Root directory where the versioned run artifacts and logs will be saved. |
"artifacts"
|
verbose_override
|
Union[bool, int, str, None]
|
Console verbosity setting configuration override. |
None
|
is_classifier
|
bool
|
Whether |
True
|
Attributes:
| Name | Type | Description |
|---|---|---|
config |
MedpipeClassifierConfig
|
The resolved configuration object driving the pipeline. |
artifact_manager |
ArtifactManager
|
Manager handling the creation and population of reproducibility artifacts. |
run_dir |
Path
|
The specific, versioned directory path for the current execution run. |
logger |
Logger
|
The configured logger instance for the orchestrator, routing to both console and the artifact directory. |
Methods:
| Name | Description |
|---|---|
ingest_data |
Loads and validates the raw dataset specified in the configuration. |
prepare_data |
Extracts labels and applies sequential splits for test and recalibration sets. |
extract_stratum_subgroup |
Extract a stratified subgroup from features (and optional target labels). |
build_preprocessor |
Constructs an sklearn Pipeline for data transformation. |
_save_reproducibility_artifacts |
Persists the resolved configuration, original TOML file, and environment state. |
_check_operation |
Validates and retrieves a preprocessing operation. |
Source code in medpipe/pipeline/orchestrator.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 | |
splits
property
splits: DataSplits
Access cached data splits.
Returns:
| Type | Description |
|---|---|
DataSplits
|
Access to the DataSplits attributes. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the splits have not been populated and 'prepare_data()' or 'run()' need to be called. |
fairness_splits
property
fairness_splits: FairnessSplits | None
Access cached fairness stratification splits.
Returns:
| Type | Description |
|---|---|
FairnessSplits or None
|
Access to the FairnessSplits attributes, or None if no
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If data has not been prepared yet and 'prepare_data()' or 'run()' need to be called. |
prepare_data
prepare_data(
**kwargs,
) -> tuple[
DataFrame,
DataFrame,
DataFrame | None,
DataFrame | None,
DataFrame,
DataFrame,
NDArray | None,
]
Ingests data, extracts labels, and performs configured train/recal/test splits.
Also populates fairness_splits with the configured fairness
stratification columns (see FairnessSplits), aligned to the same
row indices as the returned X_train/X_test/X_recal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Additional keyword arguments passed to the underlying Pandas reader function
(e.g., |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
X_train |
DataFrame
|
|
y_train |
DataFrame
|
|
X_recal |
Optional[DataFrame]
|
|
y_recal |
Optional[DataFrame]
|
|
X_test |
DataFrame
|
|
y_test |
DataFrame
|
|
groups_train |
Optional[NDArray]
|
|
Source code in medpipe/pipeline/orchestrator.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | |
ingest_data
Loads the raw dataset specified in the configuration and filters it to retain only predictors, outcomes, and configured group columns.
Fairness stratification columns (workflow.evaluation.fairness.strata)
are validated against the raw dataset here too, but are kept out of
the returned frame; they are cached separately (_fairness_raw) for
prepare_data() to align into FairnessSplits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Additional keyword arguments passed to the underlying Pandas reader function
(e.g., |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The loaded and filtered dataset. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the loaded data is not a pandas DataFrame. |
KeyError
|
If any configured required or fairness stratum column is missing from the raw dataset. |
Source code in medpipe/pipeline/orchestrator.py
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 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 | |
get_subgroup_specs
Parses workflow.evaluation.fairness settings into a dictionary
compatible with MedpipeClassifierEvaluator.extract_subgroups.
Returns:
| Name | Type | Description |
|---|---|---|
subgroup_specs |
dict of str to Any
|
Maps stratum column names either to column strings
(for discrete categorical groupings) or to lists of range bounds
defined under |
Source code in medpipe/pipeline/orchestrator.py
extract_stratum_subgroup
extract_stratum_subgroup(
X: DataFrame,
column: str,
group: Any,
y: DataFrame | None = None,
) -> tuple[DataFrame, DataFrame | None]
Extract a stratified subgroup from features (and optional target labels).
Resolves continuous range bounds or discrete categorical identifiers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame
|
Feature matrix containing the stratification column. |
required |
column
|
str
|
Name of the column defining the stratum (e.g., 'AGE', 'SEX'). |
required |
group
|
Any
|
The specific subgroup identifier or range (e.g., 'M', (18, 65), '[18, 65)'). |
required |
y
|
DataFrame
|
Corresponding ground truth label DataFrame aligned with X. Default is None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
X_subgroup |
DataFrame
|
Filtered feature DataFrame for the specified stratum group. |
y_subgroup |
DataFrame or None
|
Filtered label DataFrame matching X_subgroup index, or None if y was not provided. |
Source code in medpipe/pipeline/orchestrator.py
build_preprocessor
Constructs an sklearn Pipeline for data transformation based on the configuration.
Parses the workflow configuration to build a sequence of ColumnTransformer
objects, mapping specific operations to requested columns.
Returns:
| Type | Description |
|---|---|
Optional[Pipeline]
|
A configured scikit-learn |
Source code in medpipe/pipeline/orchestrator.py
runner
BaseRunner
Shared execution engine for training, hyperparameter tuning, and persisting outcome models, independent of outcome type.
Handles instantiating estimators via the ModelRegistry, running
GridSearchCV or standard cross-validation, and persisting the finalized
models to the run directory. Outcome-type-specific behavior (CV splitter
selection, the fitted pipeline's final step name and class, the default
metrics fallback, and any post-hoc adjustment of the fitted pipeline) is
provided by subclasses via the _final_step_name, _pipeline_cls, and
_default_metrics class attributes and the _create_cv_splitter and
_postfit hook methods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
orchestrator
|
MedpipeOrchestrator
|
The configured orchestrator instance, providing resolved configurations, preprocessing pipelines, and the execution run directory. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
orchestrator |
MedpipeOrchestrator
|
Orchestrator instance driving the environment state. |
logger |
Logger
|
Logger instance for the runner. |
fitted_models |
Dict[str, Any]
|
Dictionary storing the finalized models, keyed by outcome name. |
Methods:
| Name | Description |
|---|---|
fit_outcome |
|
groups_train=None) |
Trains and optionally post-processes a model for a single outcome. |
run |
Executes the pipelines for all configured target outcomes. |
Source code in medpipe/pipeline/runner.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 | |
fit_outcome
fit_outcome(
outcome: str,
X_train: DataFrame,
y_train: ndarray,
X_recal: DataFrame | None = None,
y_recal: ndarray | None = None,
groups_train: ndarray | None = None,
) -> Any
Trains and optionally post-processes a model for a single outcome.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outcome
|
str
|
The name of the outcome being modeled. |
required |
X_train
|
DataFrame
|
The training feature set. |
required |
y_train
|
ndarray
|
The 1D training target labels. |
required |
X_recal
|
Optional[DataFrame]
|
The recalibration feature set. |
None
|
y_recal
|
Optional[ndarray]
|
The 1D recalibration target labels. |
None
|
groups_train
|
Optional[ndarray]
|
Group labels for the training set, required if strategy is 'group'. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The fully trained model ready for evaluation. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no algorithm is specified for an outcome |
Source code in medpipe/pipeline/runner.py
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 | |
run
run(
X_train: DataFrame,
y_train_df: DataFrame,
X_recal: DataFrame | None = None,
y_recal_df: DataFrame | None = None,
groups_train: ndarray | None = None,
) -> dict[str, Any]
Executes the pipelines for all configured target outcomes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X_train
|
DataFrame
|
The training feature set. |
required |
y_train_df
|
DataFrame
|
The training targets DataFrame (can contain multiple outcome columns). |
required |
X_recal
|
Optional[DataFrame]
|
The recalibration feature set. |
None
|
y_recal_df
|
Optional[DataFrame]
|
The recalibration targets DataFrame. |
None
|
groups_train
|
Optional[ndarray]
|
Group labels for the training set. |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
A dictionary mapping outcome names to their finalized, fitted models. |
Source code in medpipe/pipeline/runner.py
MedpipeClassifierRunner
Bases: BaseRunner
Executes the training, hyperparameter tuning, and optional recalibration loops for binary classification outcomes.
The runner acts purely as an execution engine. It requests instantiated preprocessing pipelines from the orchestrator, initializes models via the ModelRegistry, handles GridSearchCV or standard cross-validation, applies post-hoc calibration, and persists the finalized models to the run directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
orchestrator
|
MedpipeOrchestrator
|
The configured orchestrator instance, providing resolved configurations, preprocessing pipelines, and the execution run directory. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
orchestrator |
MedpipeOrchestrator
|
Orchestrator instance driving the environment state. |
logger |
Logger
|
Logger instance for the runner. |
fitted_models |
Dict[str, Union[Pipeline, CalibratedClassifierCV]]
|
Dictionary storing the finalized models, keyed by outcome name. |
Methods:
| Name | Description |
|---|---|
fit_outcome |
|
groups_train=None) |
Trains, evaluates, and optionally calibrates a model for a single outcome. |
run |
Executes the pipelines for all configured target outcomes. |
Source code in medpipe/pipeline/runner.py
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 | |
MedpipeRegressorRunner
Bases: BaseRunner
Executes the training and hyperparameter tuning loops for regression outcomes.
Fitted pipelines are built as DistributionalPipeline instances so that
distributional estimators (e.g. NGBoost, OrdBoost) expose a unified
predict_dist method. Post-hoc recalibration is not supported on the
regression track, so fit_outcome returns the best fitted pipeline
unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
orchestrator
|
MedpipeOrchestrator
|
The configured orchestrator instance, providing resolved configurations, preprocessing pipelines, and the execution run directory. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
orchestrator |
MedpipeOrchestrator
|
Orchestrator instance driving the environment state. |
logger |
Logger
|
Logger instance for the runner. |
fitted_models |
Dict[str, DistributionalPipeline]
|
Dictionary storing the finalized models, keyed by outcome name. |
Methods:
| Name | Description |
|---|---|
fit_outcome |
|
groups_train=None) |
Trains a model for a single outcome. |
run |
Executes the pipelines for all configured target outcomes. |
Source code in medpipe/pipeline/runner.py
804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 | |
evaluator
Evaluator module for MedpipeClassifier machine learning models and pipelines.
Provides TRIPOD+AI compliant model evaluation, subgroup performance analysis, bootstrap confidence interval estimation, logging, and artifact management.
BaseEvaluator
Shared evaluation engine for computing point estimates and bootstrap confidence intervals across full datasets and subgroups, independent of outcome type.
Provides model resolution, subgroup extraction, TRIPOD+AI compliant
slice evaluation, and artifact persistence. Outcome-type-specific
prediction retrieval (e.g. probability/decision scores for
classification, point or distributional predictions for regression) is
provided by subclasses via the _get_predictions hook.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
orchestrator
|
MedpipeOrchestrator
|
The pipeline orchestrator instance containing workflow configuration,
run directories, and the |
required |
runner
|
BaseRunner
|
The pipeline runner instance containing the dictionary of fitted models
( |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
orchestrator |
MedpipeOrchestrator
|
Pipeline orchestrator instance. |
runner |
BaseRunner
|
Pipeline runner instance. |
fitted_models |
dict of str to object
|
Dictionary mapping outcome names to fitted estimators or pipelines. |
metrics |
list of str
|
List of metric names used during evaluation. |
n_bootstraps |
int
|
Number of bootstrap iterations. |
ci_level |
float
|
Target confidence interval level. |
random_state |
int, np.random.Generator, or None
|
Random state instance for resampling. |
n_jobs |
int or None
|
Number of parallel jobs used to compute each slice's bootstrap
resamples (see |
logger |
Logger
|
Logger instance configured under |
Methods:
| Name | Description |
|---|---|
predict |
Predict outcomes for samples in X. |
extract_subgroups |
Extract index subsets for specified data subgroups. |
evaluate |
Evaluate model performance with confidence intervals across full data and subgroups. |
Source code in medpipe/pipeline/evaluator.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 | |
predict
Predict outcomes for samples in X.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame or ndarray
|
Features dataset of shape (n_samples, n_features). |
required |
model
|
object
|
Fitted model instance. If None, resolved via |
None
|
outcome
|
str
|
Outcome key to look up in |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
y_pred |
ndarray
|
Predicted values of shape (n_samples,). |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the resolved model does not implement a |
Source code in medpipe/pipeline/evaluator.py
extract_subgroups
extract_subgroups(
X: DataFrame,
subgroup_specs: dict[
str, str | Callable[[DataFrame], Series]
],
) -> dict[str, dict[str, Index]]
Extract sample index subsets for specified data subgroups.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame
|
Input feature dataset. |
required |
subgroup_specs
|
dict of str to (str or callable)
|
Mapping where keys are subgroup category names (e.g., |
required |
Returns:
| Name | Type | Description |
|---|---|---|
subgroups |
dict of str to dict of str to pandas.Index
|
Nested dictionary structured as
|
Raises:
| Type | Description |
|---|---|
KeyError
|
If a specified column string is missing from |
TypeError
|
If a specification is neither a string nor a callable. |
Source code in medpipe/pipeline/evaluator.py
evaluate
evaluate(
X: DataFrame,
y: Series | NDArray,
outcome: str | None = None,
model: Any | None = None,
metrics: list[str] | None = None,
subgroup_specs: dict[
str, str | Callable[[DataFrame], Series]
]
| None = None,
fairness_data: DataFrame | None = None,
save_artifacts: bool = True,
) -> dict[str, Any]
Evaluate model performance across the full dataset and optional subgroups.
Computes point estimates and bootstrap confidence intervals for all requested
metrics in accordance with TRIPOD+AI guidelines. Results are optionally saved
to disk via the orchestrator's ArtifactManager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame
|
Feature dataset of shape (n_samples, n_features), used for prediction. Contains model predictors only. |
required |
y
|
Series or ndarray
|
Ground truth target values of shape (n_samples,). |
required |
outcome
|
str
|
Outcome key name. Used for logging, model resolution, and artifact saving. |
None
|
model
|
object
|
Explicit fitted model instance. If None, resolved from |
None
|
metrics
|
list of str
|
List of metrics to evaluate. If None, defaults to |
None
|
subgroup_specs
|
dict of str to (str or callable)
|
Specifications for extracting demographic/clinical subgroups. |
None
|
fairness_data
|
DataFrame
|
Fairness stratification columns aligned with |
None
|
save_artifacts
|
bool
|
Whether to write evaluation summary results to disk via |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
results |
dict of str to Any
|
Nested dictionary containing:
- |
Source code in medpipe/pipeline/evaluator.py
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 | |
MedpipeClassifierEvaluator
Bases: BaseEvaluator
Evaluation engine for MedpipeClassifier machine learning models and pipelines.
Provides standard inference interfaces (predict, predict_proba,
decision_function) and structured performance evaluation across full
datasets and extracted data subgroups. In compliance with TRIPOD+AI
reporting guidelines, evaluation metrics include bootstrap confidence
intervals. Results are automatically logged and saved to disk using the
orchestrator's ArtifactManager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
orchestrator
|
MedpipeOrchestrator
|
The pipeline orchestrator instance containing workflow configuration,
run directories, and the |
required |
runner
|
MedpipeClassifierRunner
|
The pipeline runner instance containing the dictionary of fitted models
( |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
orchestrator |
MedpipeOrchestrator
|
Pipeline orchestrator instance. |
runner |
MedpipeClassifierRunner
|
Pipeline runner instance. |
fitted_models |
dict of str to object
|
Dictionary mapping outcome names to fitted estimators or pipelines. |
metrics |
list of str
|
List of metric names used during evaluation. |
n_bootstraps |
int
|
Number of bootstrap iterations. |
ci_level |
float
|
Target confidence interval level. |
random_state |
int, np.random.Generator, or None
|
Random state instance for resampling. |
n_jobs |
int or None
|
Number of parallel jobs used to compute each slice's bootstrap
resamples (see |
logger |
Logger
|
Logger instance configured under |
Methods:
| Name | Description |
|---|---|
predict |
Predict class labels for samples in X. |
predict_proba |
Predict class probabilities for samples in X. |
decision_function |
Compute decision function scores for samples in X. |
extract_subgroups |
Extract index subsets for specified data subgroups. |
evaluate |
Evaluate model performance with confidence intervals across full data and subgroups. |
Source code in medpipe/pipeline/evaluator.py
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 | |
predict_proba
predict_proba(
X: DataFrame | NDArray,
model: Any | None = None,
outcome: str | None = None,
) -> NDArray
Predict class probabilities for samples in X.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame or ndarray
|
Features dataset of shape (n_samples, n_features). |
required |
model
|
object
|
Fitted model instance. If None, resolved via |
None
|
outcome
|
str
|
Outcome key to look up in |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
y_proba |
ndarray
|
Predicted class probabilities of shape (n_samples, n_classes) or (n_samples,). |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the resolved model does not implement a |
Source code in medpipe/pipeline/evaluator.py
decision_function
decision_function(
X: DataFrame | NDArray,
model: Any | None = None,
outcome: str | None = None,
) -> NDArray
Compute decision function scores for samples in X.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame or ndarray
|
Features dataset of shape (n_samples, n_features). |
required |
model
|
object
|
Fitted model instance. If None, resolved via |
None
|
outcome
|
str
|
Outcome key to look up in |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
scores |
ndarray
|
Confidence scores or decision function values of shape (n_samples,). |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the resolved model does not implement a |
Source code in medpipe/pipeline/evaluator.py
MedpipeRegressorEvaluator
Bases: BaseEvaluator
Evaluation engine for MedpipeRegressor machine learning models and pipelines.
Provides the standard predict inference interface and structured
performance evaluation across full datasets and extracted data
subgroups, using point predictions for metrics such as RMSE and MAE.
In compliance with TRIPOD+AI reporting guidelines, evaluation metrics
include bootstrap confidence intervals. Results are automatically
logged and saved to disk using the orchestrator's ArtifactManager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
orchestrator
|
MedpipeOrchestrator
|
The pipeline orchestrator instance containing workflow configuration,
run directories, and the |
required |
runner
|
MedpipeRegressorRunner
|
The pipeline runner instance containing the dictionary of fitted models
( |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
orchestrator |
MedpipeOrchestrator
|
Pipeline orchestrator instance. |
runner |
MedpipeRegressorRunner
|
Pipeline runner instance. |
fitted_models |
dict of str to object
|
Dictionary mapping outcome names to fitted estimators or pipelines. |
metrics |
list of str
|
List of metric names used during evaluation. |
n_bootstraps |
int
|
Number of bootstrap iterations. |
ci_level |
float
|
Target confidence interval level. |
random_state |
int, np.random.Generator, or None
|
Random state instance for resampling. |
n_jobs |
int or None
|
Number of parallel jobs used to compute each slice's bootstrap
resamples (see |
logger |
Logger
|
Logger instance configured under |
Methods:
| Name | Description |
|---|---|
predict |
Predict continuous values for samples in X. |
predict_dist |
Predict the full predictive distribution for samples in X. |
extract_subgroups |
Extract index subsets for specified data subgroups. |
evaluate |
Evaluate model performance with confidence intervals across full data and subgroups. |
Source code in medpipe/pipeline/evaluator.py
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 | |
predict_dist
predict_dist(
X: DataFrame | NDArray,
model: Any | None = None,
outcome: str | None = None,
) -> Any
Predict the full predictive distribution for samples in X.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame or ndarray
|
Features dataset of shape (n_samples, n_features). |
required |
model
|
object
|
Fitted model instance. If None, resolved via |
None
|
outcome
|
str
|
Outcome key to look up in |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The distribution object returned by the resolved model's
|
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the resolved model does not implement a |
Source code in medpipe/pipeline/evaluator.py
estimator
Pipeline subclass exposing a unified distributional prediction interface.
DistributionalPipeline
Bases: Pipeline
A scikit-learn Pipeline that exposes a unified predict_dist method,
delegating to whichever of predict_dist or pred_dist the final
estimator implements.
Different probabilistic boosting libraries name their distributional
prediction method differently (e.g. NGBoost's NGBRegressor.pred_dist,
OrdBoost's predict_dist). This subclass lets the rest of
MedPipe call a single, consistent method regardless of which library
produced the final estimator.
Adds no constructor parameters or instance state beyond Pipeline
itself, so sklearn.base.clone() (used internally by GridSearchCV
and cross_validate) preserves this subclass unchanged.
Source code in medpipe/pipeline/estimator.py
predict_dist
Predict the full predictive distribution for samples in X.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame or ndarray
|
Features dataset of shape (n_samples, n_features). |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The distribution object returned by the final estimator's
|
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the final estimator implements neither |