medpipe 0.2.0.dev0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- medpipe-0.3.0/PKG-INFO +145 -0
- medpipe-0.3.0/README.md +114 -0
- {medpipe-0.2.0.dev0 → medpipe-0.3.0}/pyproject.toml +17 -10
- medpipe-0.3.0/requirements.txt +14 -0
- medpipe-0.3.0/src/medpipe/__init__.py +46 -0
- medpipe-0.3.0/src/medpipe/_types.py +39 -0
- medpipe-0.3.0/src/medpipe/data/__init__.py +9 -0
- medpipe-0.3.0/src/medpipe/data/transformers.py +87 -0
- medpipe-0.3.0/src/medpipe/data/utils.py +269 -0
- medpipe-0.3.0/src/medpipe/metrics/__init__.py +16 -0
- medpipe-0.3.0/src/medpipe/metrics/core.py +364 -0
- medpipe-0.3.0/src/medpipe/metrics/plots.py +722 -0
- medpipe-0.3.0/src/medpipe/models/__init__.py +9 -0
- medpipe-0.3.0/src/medpipe/models/core.py +157 -0
- medpipe-0.3.0/src/medpipe/pipeline/pipeline.py +1519 -0
- {medpipe-0.2.0.dev0 → medpipe-0.3.0}/src/medpipe/utils/__init__.py +1 -1
- medpipe-0.3.0/src/medpipe/utils/config.py +542 -0
- {medpipe-0.2.0.dev0 → medpipe-0.3.0}/src/medpipe/utils/exceptions.py +34 -37
- medpipe-0.3.0/src/medpipe/utils/io.py +126 -0
- medpipe-0.3.0/src/medpipe.egg-info/PKG-INFO +145 -0
- {medpipe-0.2.0.dev0 → medpipe-0.3.0}/src/medpipe.egg-info/SOURCES.txt +2 -22
- medpipe-0.3.0/src/medpipe.egg-info/requires.txt +14 -0
- medpipe-0.2.0.dev0/PKG-INFO +0 -157
- medpipe-0.2.0.dev0/README.md +0 -131
- medpipe-0.2.0.dev0/requirements.txt +0 -9
- medpipe-0.2.0.dev0/src/medpipe/__init__.py +0 -55
- medpipe-0.2.0.dev0/src/medpipe/_types.py +0 -50
- medpipe-0.2.0.dev0/src/medpipe/data/__init__.py +0 -15
- medpipe-0.2.0.dev0/src/medpipe/data/db.py +0 -116
- medpipe-0.2.0.dev0/src/medpipe/data/preprocessing.py +0 -202
- medpipe-0.2.0.dev0/src/medpipe/data/preprocessor.py +0 -191
- medpipe-0.2.0.dev0/src/medpipe/data/sampler.py +0 -710
- medpipe-0.2.0.dev0/src/medpipe/data/utils.py +0 -269
- medpipe-0.2.0.dev0/src/medpipe/data/weighting.py +0 -251
- medpipe-0.2.0.dev0/src/medpipe/metrics/__init__.py +0 -21
- medpipe-0.2.0.dev0/src/medpipe/metrics/core.py +0 -363
- medpipe-0.2.0.dev0/src/medpipe/metrics/plots.py +0 -450
- medpipe-0.2.0.dev0/src/medpipe/models/__init__.py +0 -11
- medpipe-0.2.0.dev0/src/medpipe/models/calibrators.py +0 -345
- medpipe-0.2.0.dev0/src/medpipe/models/core.py +0 -297
- medpipe-0.2.0.dev0/src/medpipe/models/predictors.py +0 -280
- medpipe-0.2.0.dev0/src/medpipe/pipeline/pipeline.py +0 -822
- medpipe-0.2.0.dev0/src/medpipe/utils/config.py +0 -206
- medpipe-0.2.0.dev0/src/medpipe/utils/io.py +0 -108
- medpipe-0.2.0.dev0/src/medpipe.egg-info/PKG-INFO +0 -157
- medpipe-0.2.0.dev0/src/medpipe.egg-info/requires.txt +0 -9
- medpipe-0.2.0.dev0/test/test_data_db.py +0 -90
- medpipe-0.2.0.dev0/test/test_data_preprocessing.py +0 -132
- medpipe-0.2.0.dev0/test/test_data_preprocessor.py +0 -104
- medpipe-0.2.0.dev0/test/test_data_sampler.py +0 -582
- medpipe-0.2.0.dev0/test/test_data_utils.py +0 -225
- medpipe-0.2.0.dev0/test/test_data_weighting.py +0 -253
- medpipe-0.2.0.dev0/test/test_models_calibrators.py +0 -38
- medpipe-0.2.0.dev0/test/test_models_core.py +0 -84
- medpipe-0.2.0.dev0/test/test_models_predictors.py +0 -34
- medpipe-0.2.0.dev0/test/test_pipeline_pipeline.py +0 -74
- medpipe-0.2.0.dev0/test/test_utils_config.py +0 -224
- medpipe-0.2.0.dev0/test/test_utils_exceptions.py +0 -213
- medpipe-0.2.0.dev0/test/test_utils_io.py +0 -76
- medpipe-0.2.0.dev0/test/test_utils_logger.py +0 -44
- {medpipe-0.2.0.dev0 → medpipe-0.3.0}/LICENSE +0 -0
- {medpipe-0.2.0.dev0 → medpipe-0.3.0}/setup.cfg +0 -0
- {medpipe-0.2.0.dev0 → medpipe-0.3.0}/src/medpipe/pipeline/__init__.py +0 -0
- {medpipe-0.2.0.dev0 → medpipe-0.3.0}/src/medpipe/py.typed +0 -0
- {medpipe-0.2.0.dev0 → medpipe-0.3.0}/src/medpipe/utils/logger.py +0 -0
- {medpipe-0.2.0.dev0 → medpipe-0.3.0}/src/medpipe.egg-info/dependency_links.txt +0 -0
- {medpipe-0.2.0.dev0 → medpipe-0.3.0}/src/medpipe.egg-info/top_level.txt +0 -0
medpipe-0.3.0/PKG-INFO
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: medpipe
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: A package for clinical AI pipeline development
|
|
5
|
+
Author-email: Mathias Roesler <mathias.roesler@auckland.co.nz>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Repository, https://github.com/Surgical-Recovery-and-Safety-Lab/medpipe
|
|
8
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
9
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
13
|
+
Requires-Python: >=3.12
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: imbalanced_learn>=0.14.1
|
|
17
|
+
Requires-Dist: imblearn==0.0
|
|
18
|
+
Requires-Dist: matplotlib>=3.10.8
|
|
19
|
+
Requires-Dist: numpy>=2.4.2
|
|
20
|
+
Requires-Dist: pandas>=2.3.3
|
|
21
|
+
Requires-Dist: pytest>=9.0.1
|
|
22
|
+
Requires-Dist: pytest-mock>=3.15.1
|
|
23
|
+
Requires-Dist: scikit_learn==1.8.0
|
|
24
|
+
Requires-Dist: scipy>=1.17.0
|
|
25
|
+
Requires-Dist: pyarrow>=23.0.1
|
|
26
|
+
Requires-Dist: pydantic>=2.13.4
|
|
27
|
+
Requires-Dist: ml_insights>=1.1.0
|
|
28
|
+
Requires-Dist: ngboost>=0.5.10
|
|
29
|
+
Requires-Dist: pytest-mock>=3.15.1
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
|
|
32
|
+
# medpipe
|
|
33
|
+
|
|
34
|
+

|
|
35
|
+
[](https://www.python.org/downloads/)
|
|
36
|
+
[](https://github.com/Surgical-Recovery-and-Safety-Lab/medpipe/actions/workflows/run_test.yml)
|
|
37
|
+
## Table of content
|
|
38
|
+
1. [Overview](#overview)
|
|
39
|
+
2. [Installation](#installation)
|
|
40
|
+
3. [Usage](#usage)
|
|
41
|
+
1. [Preprocessing operations](#preprocess)
|
|
42
|
+
2. [Models](#models)
|
|
43
|
+
3. [Recalibration](#recalibration)
|
|
44
|
+
4. [Metrics](#metrics)
|
|
45
|
+
5. [Plots](#plots)
|
|
46
|
+
5. [Examples](#examples)
|
|
47
|
+
|
|
48
|
+
## Overview
|
|
49
|
+
The **medpipe** package is a layer to help create AI models (classifiers and regressors) for clinical applications from tabular data. It covers data loading and preprocessing, model creation and training, recalibration, and visualisation.
|
|
50
|
+
___
|
|
51
|
+
## Installation
|
|
52
|
+
|
|
53
|
+
To install **medpipe** use pip:
|
|
54
|
+
```
|
|
55
|
+
$ pip install medpipe
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
or clone the GitHub repository and install the package with pip:
|
|
59
|
+
```
|
|
60
|
+
$ git clone git@github.com:Surgical-Recovery-and-Safety-Lab/medpipe.git
|
|
61
|
+
$ cd medpipe
|
|
62
|
+
$ pip install .
|
|
63
|
+
```
|
|
64
|
+
**NOTE**: It is recommended to use a virtual environment (venv) to install this package.
|
|
65
|
+
|
|
66
|
+
Ensure that the installation was successful and that all tests pass by running the following command in the medpipe directory:
|
|
67
|
+
```
|
|
68
|
+
$ pytest
|
|
69
|
+
```
|
|
70
|
+
___
|
|
71
|
+
|
|
72
|
+
## Usage
|
|
73
|
+
This package was tested on a Linux distribution (Ubuntu 24.04) with Python v3.12.3. The [sckit-learn](https://scikit-learn.org/stable/index.html) was used as the base of most of the code.
|
|
74
|
+
|
|
75
|
+
A MedpipePipeline contains the preprocessing operations, a model for each prediction outcome, and a recalibration model (if specified) for each outcome. Thus, with only a few lines of code, several models can be created and fitted using the same data.
|
|
76
|
+
|
|
77
|
+
### Preprocessing operations
|
|
78
|
+
Preprocessing operations are chained and applied sequentially. Available operations are listed in the [sklearn.preprocessing](https://scikit-learn.org/stable/api/sklearn.preprocessing.html) and [sklearn.impute](https://scikit-learn.org/stable/api/sklearn.impute.html) modules.
|
|
79
|
+
|
|
80
|
+
### Models
|
|
81
|
+
Any model from the [sklearn.ensemble](https://scikit-learn.org/stable/api/sklearn.ensemble.html), [sklearn.linear_model](https://scikit-learn.org/stable/api/sklearn.linear_model.html), and [sklearn.isotonic](https://scikit-learn.org/stable/api/sklearn.isotonic.html) modules are available. Additionally, models from the [ngboost](https://stanfordmlgroup.github.io/ngboost/intro) package can be used.
|
|
82
|
+
|
|
83
|
+
**NOTE:** The package can handle binary classifiers and regressors. However, handling of regressors is not as developed yet.
|
|
84
|
+
|
|
85
|
+
### Recalibration
|
|
86
|
+
Two recalibration models are available: logistic regression (Platt scaling), and isotonic regression.
|
|
87
|
+
|
|
88
|
+
### Metrics
|
|
89
|
+
The list of available metrics is the following:
|
|
90
|
+
|
|
91
|
+
| Metric | Description |
|
|
92
|
+
| :--- | :--- |
|
|
93
|
+
| Accuracy | Proportion of all classifications that were correct. |
|
|
94
|
+
| Recall | Proportion of all actual positives that were classified correctly (true positive rate). |
|
|
95
|
+
| Precision | Proportion of all the positive classifications that are actually positive. |
|
|
96
|
+
| F1 score | Harmonic mean of precision and recall. |
|
|
97
|
+
| AUROC | Area under the ROC curve. |
|
|
98
|
+
| AP | Area under the precision-recall curve. |
|
|
99
|
+
| Log loss | Logarithmic loss. |
|
|
100
|
+
| Brier score | Brier score loss. |
|
|
101
|
+
| ICI | Integrated calibration index. |
|
|
102
|
+
| RMSE | Root mean squared error. |
|
|
103
|
+
| MAE| Mean absolute error. |
|
|
104
|
+
|
|
105
|
+
**NOTE:** Metrics can be added by editing the METRIC_MAPPING map in the metrics/core.py module.
|
|
106
|
+
|
|
107
|
+
### Plots
|
|
108
|
+
There are four different plots that can be generated (mainly for classifiers):
|
|
109
|
+
1. Probability distribution, histrogram of predicted probabilities;
|
|
110
|
+
2. ROC curve, receiver operating characteristic curve;
|
|
111
|
+
3. Reliability diagram, classifier calibration curve;
|
|
112
|
+
4. Fairness heatmap, heatmap of differences for different strata to assess model bias.
|
|
113
|
+
|
|
114
|
+
___
|
|
115
|
+
## Examples
|
|
116
|
+
|
|
117
|
+
Minimal example based on configuration files:
|
|
118
|
+
``` py linenums="1"
|
|
119
|
+
import medpipe as mp
|
|
120
|
+
|
|
121
|
+
config_path = "config-examples/HGBc_config.toml"
|
|
122
|
+
pipe = mp.MedpipePipeline(config_path, logger=None)
|
|
123
|
+
pipe.run() # Run pipeline based on configuration
|
|
124
|
+
pipe.save() # Save pipeline
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Example allowing the user more control over the data and plots:
|
|
128
|
+
``` py linenums="1"
|
|
129
|
+
import medpipe as mp
|
|
130
|
+
|
|
131
|
+
config_path = "config-examples/HGBc_config.toml"
|
|
132
|
+
pipe = mp.MedpipePipeline(config_path, logger=None)
|
|
133
|
+
data = load_data(pipe.medpipe_config.data.path) # Load the data
|
|
134
|
+
|
|
135
|
+
# Get the different data sets
|
|
136
|
+
X_train, y_train, X_test, y_test, X_recal, y_recal, _ = pipe.get_data_sets(data)
|
|
137
|
+
pipe.fit(X_train, y_train, X_recal, y_recal) # Fit the pipeline
|
|
138
|
+
|
|
139
|
+
# Make predictions for each outcome and plot some figures
|
|
140
|
+
for outcome in pipe.outcomes:
|
|
141
|
+
y_preds = pipe.predict_proba(X_test, outcome)[0]
|
|
142
|
+
mp.plot_ROC_curve(y_test, y_preds, "ROC curve")
|
|
143
|
+
mp.plot_reliability_diagram(y_test, y_preds, "Calibration", strategy="quantile")
|
|
144
|
+
|
|
145
|
+
```
|
medpipe-0.3.0/README.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# medpipe
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
[](https://www.python.org/downloads/)
|
|
5
|
+
[](https://github.com/Surgical-Recovery-and-Safety-Lab/medpipe/actions/workflows/run_test.yml)
|
|
6
|
+
## Table of content
|
|
7
|
+
1. [Overview](#overview)
|
|
8
|
+
2. [Installation](#installation)
|
|
9
|
+
3. [Usage](#usage)
|
|
10
|
+
1. [Preprocessing operations](#preprocess)
|
|
11
|
+
2. [Models](#models)
|
|
12
|
+
3. [Recalibration](#recalibration)
|
|
13
|
+
4. [Metrics](#metrics)
|
|
14
|
+
5. [Plots](#plots)
|
|
15
|
+
5. [Examples](#examples)
|
|
16
|
+
|
|
17
|
+
## Overview
|
|
18
|
+
The **medpipe** package is a layer to help create AI models (classifiers and regressors) for clinical applications from tabular data. It covers data loading and preprocessing, model creation and training, recalibration, and visualisation.
|
|
19
|
+
___
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
To install **medpipe** use pip:
|
|
23
|
+
```
|
|
24
|
+
$ pip install medpipe
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
or clone the GitHub repository and install the package with pip:
|
|
28
|
+
```
|
|
29
|
+
$ git clone git@github.com:Surgical-Recovery-and-Safety-Lab/medpipe.git
|
|
30
|
+
$ cd medpipe
|
|
31
|
+
$ pip install .
|
|
32
|
+
```
|
|
33
|
+
**NOTE**: It is recommended to use a virtual environment (venv) to install this package.
|
|
34
|
+
|
|
35
|
+
Ensure that the installation was successful and that all tests pass by running the following command in the medpipe directory:
|
|
36
|
+
```
|
|
37
|
+
$ pytest
|
|
38
|
+
```
|
|
39
|
+
___
|
|
40
|
+
|
|
41
|
+
## Usage
|
|
42
|
+
This package was tested on a Linux distribution (Ubuntu 24.04) with Python v3.12.3. The [sckit-learn](https://scikit-learn.org/stable/index.html) was used as the base of most of the code.
|
|
43
|
+
|
|
44
|
+
A MedpipePipeline contains the preprocessing operations, a model for each prediction outcome, and a recalibration model (if specified) for each outcome. Thus, with only a few lines of code, several models can be created and fitted using the same data.
|
|
45
|
+
|
|
46
|
+
### Preprocessing operations
|
|
47
|
+
Preprocessing operations are chained and applied sequentially. Available operations are listed in the [sklearn.preprocessing](https://scikit-learn.org/stable/api/sklearn.preprocessing.html) and [sklearn.impute](https://scikit-learn.org/stable/api/sklearn.impute.html) modules.
|
|
48
|
+
|
|
49
|
+
### Models
|
|
50
|
+
Any model from the [sklearn.ensemble](https://scikit-learn.org/stable/api/sklearn.ensemble.html), [sklearn.linear_model](https://scikit-learn.org/stable/api/sklearn.linear_model.html), and [sklearn.isotonic](https://scikit-learn.org/stable/api/sklearn.isotonic.html) modules are available. Additionally, models from the [ngboost](https://stanfordmlgroup.github.io/ngboost/intro) package can be used.
|
|
51
|
+
|
|
52
|
+
**NOTE:** The package can handle binary classifiers and regressors. However, handling of regressors is not as developed yet.
|
|
53
|
+
|
|
54
|
+
### Recalibration
|
|
55
|
+
Two recalibration models are available: logistic regression (Platt scaling), and isotonic regression.
|
|
56
|
+
|
|
57
|
+
### Metrics
|
|
58
|
+
The list of available metrics is the following:
|
|
59
|
+
|
|
60
|
+
| Metric | Description |
|
|
61
|
+
| :--- | :--- |
|
|
62
|
+
| Accuracy | Proportion of all classifications that were correct. |
|
|
63
|
+
| Recall | Proportion of all actual positives that were classified correctly (true positive rate). |
|
|
64
|
+
| Precision | Proportion of all the positive classifications that are actually positive. |
|
|
65
|
+
| F1 score | Harmonic mean of precision and recall. |
|
|
66
|
+
| AUROC | Area under the ROC curve. |
|
|
67
|
+
| AP | Area under the precision-recall curve. |
|
|
68
|
+
| Log loss | Logarithmic loss. |
|
|
69
|
+
| Brier score | Brier score loss. |
|
|
70
|
+
| ICI | Integrated calibration index. |
|
|
71
|
+
| RMSE | Root mean squared error. |
|
|
72
|
+
| MAE| Mean absolute error. |
|
|
73
|
+
|
|
74
|
+
**NOTE:** Metrics can be added by editing the METRIC_MAPPING map in the metrics/core.py module.
|
|
75
|
+
|
|
76
|
+
### Plots
|
|
77
|
+
There are four different plots that can be generated (mainly for classifiers):
|
|
78
|
+
1. Probability distribution, histrogram of predicted probabilities;
|
|
79
|
+
2. ROC curve, receiver operating characteristic curve;
|
|
80
|
+
3. Reliability diagram, classifier calibration curve;
|
|
81
|
+
4. Fairness heatmap, heatmap of differences for different strata to assess model bias.
|
|
82
|
+
|
|
83
|
+
___
|
|
84
|
+
## Examples
|
|
85
|
+
|
|
86
|
+
Minimal example based on configuration files:
|
|
87
|
+
``` py linenums="1"
|
|
88
|
+
import medpipe as mp
|
|
89
|
+
|
|
90
|
+
config_path = "config-examples/HGBc_config.toml"
|
|
91
|
+
pipe = mp.MedpipePipeline(config_path, logger=None)
|
|
92
|
+
pipe.run() # Run pipeline based on configuration
|
|
93
|
+
pipe.save() # Save pipeline
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Example allowing the user more control over the data and plots:
|
|
97
|
+
``` py linenums="1"
|
|
98
|
+
import medpipe as mp
|
|
99
|
+
|
|
100
|
+
config_path = "config-examples/HGBc_config.toml"
|
|
101
|
+
pipe = mp.MedpipePipeline(config_path, logger=None)
|
|
102
|
+
data = load_data(pipe.medpipe_config.data.path) # Load the data
|
|
103
|
+
|
|
104
|
+
# Get the different data sets
|
|
105
|
+
X_train, y_train, X_test, y_test, X_recal, y_recal, _ = pipe.get_data_sets(data)
|
|
106
|
+
pipe.fit(X_train, y_train, X_recal, y_recal) # Fit the pipeline
|
|
107
|
+
|
|
108
|
+
# Make predictions for each outcome and plot some figures
|
|
109
|
+
for outcome in pipe.outcomes:
|
|
110
|
+
y_preds = pipe.predict_proba(X_test, outcome)[0]
|
|
111
|
+
mp.plot_ROC_curve(y_test, y_preds, "ROC curve")
|
|
112
|
+
mp.plot_reliability_diagram(y_test, y_preds, "Calibration", strategy="quantile")
|
|
113
|
+
|
|
114
|
+
```
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
[build-system]
|
|
2
|
-
build-backend = "setuptools.build_meta"
|
|
3
|
-
requires = [ "setuptools>=80.9" ]
|
|
4
|
-
|
|
5
1
|
[project]
|
|
6
2
|
name = "medpipe"
|
|
7
|
-
version = "0.
|
|
3
|
+
version = "0.3.0"
|
|
8
4
|
description = "A package for clinical AI pipeline development"
|
|
9
5
|
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.12"
|
|
10
7
|
license = "Apache-2.0"
|
|
11
|
-
license-files = [
|
|
8
|
+
license-files = ["LICEN[CS]E*"]
|
|
12
9
|
authors = [
|
|
13
10
|
{ name = "Mathias Roesler", email = "mathias.roesler@auckland.co.nz" },
|
|
14
11
|
]
|
|
15
|
-
requires-python = ">=3.12"
|
|
16
12
|
classifiers = [
|
|
17
13
|
"Operating System :: POSIX :: Linux",
|
|
18
14
|
"Programming Language :: Python :: 3 :: Only",
|
|
@@ -20,10 +16,21 @@ classifiers = [
|
|
|
20
16
|
"Programming Language :: Python :: 3.13",
|
|
21
17
|
"Programming Language :: Python :: 3.14",
|
|
22
18
|
]
|
|
23
|
-
dynamic = [ "dependencies" ]
|
|
24
19
|
urls.Repository = "https://github.com/Surgical-Recovery-and-Safety-Lab/medpipe"
|
|
20
|
+
dynamic = ["dependencies"]
|
|
21
|
+
|
|
22
|
+
[build-system]
|
|
23
|
+
requires = ["setuptools>=80.9"]
|
|
24
|
+
build-backend = "setuptools.build_meta"
|
|
25
25
|
|
|
26
26
|
[tool.setuptools]
|
|
27
27
|
package-dir = { "" = "src" }
|
|
28
|
-
packages = [
|
|
29
|
-
|
|
28
|
+
packages = [
|
|
29
|
+
"medpipe",
|
|
30
|
+
"medpipe.data",
|
|
31
|
+
"medpipe.models",
|
|
32
|
+
"medpipe.metrics",
|
|
33
|
+
"medpipe.pipeline",
|
|
34
|
+
"medpipe.utils"
|
|
35
|
+
]
|
|
36
|
+
dynamic.dependencies = { file = ["requirements.txt"] }
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
imbalanced_learn>=0.14.1
|
|
2
|
+
imblearn==0.0
|
|
3
|
+
matplotlib>=3.10.8
|
|
4
|
+
numpy>=2.4.2
|
|
5
|
+
pandas>=2.3.3
|
|
6
|
+
pytest>=9.0.1
|
|
7
|
+
pytest-mock>=3.15.1
|
|
8
|
+
scikit_learn==1.8.0
|
|
9
|
+
scipy>=1.17.0
|
|
10
|
+
pyarrow>=23.0.1
|
|
11
|
+
pydantic>=2.13.4
|
|
12
|
+
ml_insights>=1.1.0
|
|
13
|
+
ngboost>=0.5.10
|
|
14
|
+
pytest-mock>=3.15.1
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""
|
|
2
|
+
medpipe module
|
|
3
|
+
|
|
4
|
+
submodules:
|
|
5
|
+
- data: contains data related functions
|
|
6
|
+
- metrics: contains model metric functions
|
|
7
|
+
- models: contains model creation functions
|
|
8
|
+
- pipeline: contains pipeline functions
|
|
9
|
+
- utils: contains utility functions
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from .data import extract_labels
|
|
13
|
+
from .metrics import (
|
|
14
|
+
plot_probability_distribution,
|
|
15
|
+
plot_reliability_diagram,
|
|
16
|
+
plot_ROC_curve,
|
|
17
|
+
plot_strata_heatmap,
|
|
18
|
+
print_metrics,
|
|
19
|
+
)
|
|
20
|
+
from .models import load_pipeline, save_pipeline
|
|
21
|
+
from .pipeline.pipeline import MedpipePipeline
|
|
22
|
+
from .utils import (
|
|
23
|
+
exception_handler,
|
|
24
|
+
load_data,
|
|
25
|
+
print_message,
|
|
26
|
+
read_toml_configuration,
|
|
27
|
+
setup_logger,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
__all__ = [
|
|
31
|
+
"MedpipePipeline",
|
|
32
|
+
"exception_handler",
|
|
33
|
+
"load_data",
|
|
34
|
+
"print_message",
|
|
35
|
+
"read_toml_configuration",
|
|
36
|
+
"setup_logger",
|
|
37
|
+
"load_pipeline",
|
|
38
|
+
"save_pipeline",
|
|
39
|
+
"plot_probability_distribution",
|
|
40
|
+
"plot_reliability_diagram",
|
|
41
|
+
"plot_ROC_curve",
|
|
42
|
+
"plot_strata_heatmap",
|
|
43
|
+
"print_metrics",
|
|
44
|
+
"extract_labels",
|
|
45
|
+
]
|
|
46
|
+
__version__ = "v0.3.0"
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Medpipe typings.
|
|
3
|
+
|
|
4
|
+
This module provides special types defined for the medpipe package.
|
|
5
|
+
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from typing import TYPE_CHECKING, Annotated, Literal, TypeAlias
|
|
11
|
+
|
|
12
|
+
import numpy as np
|
|
13
|
+
import numpy.typing as npt
|
|
14
|
+
import pandas as pd
|
|
15
|
+
from scipy.sparse import csr_array, csr_matrix
|
|
16
|
+
|
|
17
|
+
if TYPE_CHECKING:
|
|
18
|
+
from medpipe.utils.config import (
|
|
19
|
+
DataConfig,
|
|
20
|
+
HyperparameterConfig,
|
|
21
|
+
MedpipeConfig,
|
|
22
|
+
TopLevelConfig,
|
|
23
|
+
WorkflowConfig,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
# ==============================================================================
|
|
27
|
+
# CORE PIPELINE & DATA TYPES
|
|
28
|
+
# ==============================================================================
|
|
29
|
+
|
|
30
|
+
# Define data and label types
|
|
31
|
+
SingleClassLabels: TypeAlias = Annotated[npt.NDArray[np.integer], Literal["N"]]
|
|
32
|
+
MultiClassLabels: TypeAlias = Annotated[npt.NDArray[np.integer], Literal["N", "C"]]
|
|
33
|
+
Labels: TypeAlias = SingleClassLabels | MultiClassLabels
|
|
34
|
+
TransformedData: TypeAlias = pd.DataFrame | npt.NDArray | csr_matrix | csr_array
|
|
35
|
+
|
|
36
|
+
# Define a generic config type as a union
|
|
37
|
+
Config: TypeAlias = (
|
|
38
|
+
"MedpipeConfig | TopLevelConfig | DataConfig | WorkflowConfig | HyperparameterConfig"
|
|
39
|
+
)
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Transformers functions module.
|
|
3
|
+
|
|
4
|
+
This module provides transformers for regressors.
|
|
5
|
+
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from typing import TYPE_CHECKING
|
|
11
|
+
|
|
12
|
+
import numpy as np
|
|
13
|
+
from sklearn.base import BaseEstimator, TransformerMixin
|
|
14
|
+
|
|
15
|
+
if TYPE_CHECKING:
|
|
16
|
+
import numpy.typing as npt
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class BoundedLogitTransformer(BaseEstimator, TransformerMixin):
|
|
20
|
+
"""
|
|
21
|
+
Class that transforms data to safely bound it in the logit space.
|
|
22
|
+
|
|
23
|
+
Attributes
|
|
24
|
+
----------
|
|
25
|
+
max_value : float, default: 1.0
|
|
26
|
+
Max value in the data, needed for back-transformation.
|
|
27
|
+
epsilon : float, default: 1e-7
|
|
28
|
+
Value for clipping to avoid log(0).
|
|
29
|
+
|
|
30
|
+
Methods
|
|
31
|
+
-------
|
|
32
|
+
fit(y)
|
|
33
|
+
Needed for compatibility.
|
|
34
|
+
transform(y)
|
|
35
|
+
Transform data from the original space into the logit space.
|
|
36
|
+
inverse_transform(y)
|
|
37
|
+
Transforms data from the logit space back to the original space.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
def __init__(self, max_value: float = 1.0, epsilon: float = 1e-7) -> None:
|
|
41
|
+
self.max_value = max_value
|
|
42
|
+
self.epsilon = epsilon # To prevent log(0) or division by zero
|
|
43
|
+
|
|
44
|
+
def fit(self, y: npt.NDArray) -> "BoundedLogitTransformer":
|
|
45
|
+
"""Needed for compatibility."""
|
|
46
|
+
return self
|
|
47
|
+
|
|
48
|
+
def transform(self, y: npt.NDArray) -> npt.NDArray:
|
|
49
|
+
"""
|
|
50
|
+
Transform data from the original space into the
|
|
51
|
+
logit space.
|
|
52
|
+
|
|
53
|
+
The data is clipped to avoid log(0).
|
|
54
|
+
|
|
55
|
+
Parameters
|
|
56
|
+
----------
|
|
57
|
+
y : npt.NDArray
|
|
58
|
+
Data to transform into the logit space.
|
|
59
|
+
|
|
60
|
+
Returns
|
|
61
|
+
-------
|
|
62
|
+
y_transformed : npt.NDArray
|
|
63
|
+
Transformed data in the logit space.
|
|
64
|
+
|
|
65
|
+
"""
|
|
66
|
+
self.max_value = np.max(y) # Save max value
|
|
67
|
+
y_scaled = np.clip(y / self.max_value, self.epsilon, 1 - self.epsilon)
|
|
68
|
+
return np.log(y_scaled / (1 - y_scaled))
|
|
69
|
+
|
|
70
|
+
def inverse_transform(self, y: npt.NDArray) -> npt.NDArray:
|
|
71
|
+
"""
|
|
72
|
+
Transforms data from the logit space back to the
|
|
73
|
+
original space.
|
|
74
|
+
|
|
75
|
+
Parameters
|
|
76
|
+
----------
|
|
77
|
+
y : npt.NDArray
|
|
78
|
+
Values in the logit space to be transformed.
|
|
79
|
+
|
|
80
|
+
Returns
|
|
81
|
+
-------
|
|
82
|
+
y_transformed : npt.NDArray
|
|
83
|
+
Back-transformed y into the original space.
|
|
84
|
+
|
|
85
|
+
"""
|
|
86
|
+
exp_y = np.exp(y)
|
|
87
|
+
return (exp_y / (1 + exp_y)) * self.max_value
|