ROC aggregator
Project description
roc-aggregator
Aggregates multiple Receiver Operating Characteristic (ROC) curves obtained from different sources into one global ROC. Additionally, it’s also possible to calculate the aggregated precision-recall (PR) curve.
Motivation
The ROC and the AUC (Area Under the Curve) can be essential metrics when evaluating a model. In situations where there is a parallelization of the model development, such as federated learning, it becomes relevant to obtain precise measures for these metrics. These approaches usually produce partial results that require aggregation methods to get the complete picture. The ROCaggregator appears in this context, allowing to compute the precise ROC curve from the partial results.
Usage
Install the package using one of the following options:
- pip3:
pip3 install roc-aggregator - this repository
pip3 install .
Example:
A complete example of the usage of the roc-aggregator can be found here.
- Obtain the global ROC curve from different sources by providing the false positive rate (fpr), true positive rate (tpr), thresholds (thresh), the total number of negative samples, and the total number of samples from each source:
from roc_aggregator import roc_curve
fpr_1 = [0, 0, 0, 0, 0.002, ...] # false positive rate values for each threshold
tpr_1 = [0, 0.004, 0.008, 0.012, 0.016, ...] # true positive rate values for each threshold
thresh_1 = [0.9994038, 0.9986345, 0.99847864, 0.99575908, 0.99567612, ...] # thresholds used
negative_count_1 = np.count_nonzero(y1 == 0) # count the number of negative labels
total_count_1 = len(y1) # total number of labels
...
# ROC
fpr, tpr, thresh_stack = roc_curve(
[fpr_1, fpr_2, ...],
[tpr_1, tpr_2, ...],
[thresh_1, thresh_2, ...],
[negative_count_1, negative_count_2, ...],
[total_count_1, total_count_2, ...]
)
# Precision-Recall
pre, recall, thresh_stack = precision_recall_curve(
[fpr_1, fpr_2, ...],
[tpr_1, tpr_2, ...],
[thresh_1, thresh_2, ...],
[negative_count_1, negative_count_2, ...],
[total_count_1, total_count_2, ...]
)
- Calculate the AUC using numpy:
import numpy as np
np.trapz(tpr, fpr)
Visualization
import matplotlib.pyplot as plt
plt.style.use('seaborn')
plt.plot(fpr, tpr, color=color, label=label, linestyle=linestyle)
plt.legend()
plt.title('ROC curve')
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive rate')
plt.show()
Testing
Unit tests are available at /roc-aggregator/tests.
Install the dependencies required and run the tests using pytest or python3 setup.py test.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file roc_aggregator-1.1.2.tar.gz.
File metadata
- Download URL: roc_aggregator-1.1.2.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7bbaf4d0fb1efa2fa7af15098927fd9af3020d9e82a238f8fee627e0eec1237a
|
|
| MD5 |
40cecdec6b329f3a3a2543df9534418f
|
|
| BLAKE2b-256 |
0f4cc0f54cca0558a2a6fcef78e32c8e6126a8632e78d1473d522d1e57a0b52a
|
File details
Details for the file roc_aggregator-1.1.2-py3-none-any.whl.
File metadata
- Download URL: roc_aggregator-1.1.2-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ef0c673b69679a94a22e8ab4edd5294b899c79bf259052557526cfdd7fc42ee
|
|
| MD5 |
fa45f6be631cf139fe509f5f81e8d521
|
|
| BLAKE2b-256 |
8270a2e92d184377d3a97aed17f50eb1fa9231a718a7ea44a937a6bfe8287d81
|