Skip to main content

Trustworthiness metrics and calibration tools predictive models

Project description

TrustPy - Trustworthiness Python

Conda-Forge / PyPI package providing a Python implementation of trustworthiness quantification metrics for predictive models (e.g., DNNs):

The implementation is flexible and works out-the-box.

Installation

Recommended 1: Install via Conda-Forge

The easiest way to install nettrustscore is via Conda-Forge, which handles all dependencies automatically. Run the following command:

conda install -c conda-forge nettrustscore

Recommended 2: Install via PyPI (pip install)

If you prefer using pip (PyPI), you can install directly:

pip install nettrustscore

Alternative: Manual Installation

If you prefer to install the package manually or are not using Conda, you can install the required dependencies and clone the repository.

Install Dependencies

  • NumPy: For numerical calculations.
  • Matplotlib: For plotting the trust spectrum.
  • Scikit-learn: For Kernel Density Estimation (KDE) in trust density estimation.

Install them via conda:

conda install numpy matplotlib scikit-learn

or

Install them via pip:

pip install numpy matplotlib scikit-learn

Clone the Repository

git clone https://github.com/yaniker/nettrustscore-python.git
cd nettrustscore-python

Example Usage

from trustquant import NTS, CNTS #This is how the package is imported.
import numpy as np

# Example oracle and predictions
oracle = np.array([0, 0, 1, 2, 2, 0, 1])  # True labels
predictions = np.array([
    [0.8, 0.1, 0.1],  # Correct, high confidence
    [1.0, 0.0, 0.0],  # Correct, high confidence
    [0.2, 0.7, 0.1],  # Correct, high confidence
    [0.1, 0.2, 0.7],  # Correct, high confidence
    [0.1, 0.4, 0.5],  # Correct, lower confidence
    [0.1, 0.8, 0.1],  # Incorrect, high confidence
    [0.3, 0.3, 0.4]   # Incorrect, low confidence
]
) #Replace this with your model's predictions (`predictions = model.predict()`)

# FOR NETTRUSTSCORE #
# Initialize with default parameters
nts = NTS(oracle, predictions) #This is how you initialize. trust_spectrum = True will save trust spectrum to the directory under "trust_spectrum.png"
nts_scores_dict = nts.compute() # Computes trustworthiness for each class and overall.
print(nts_scores_dict)

# FOR CONDITIONAL NETTRUSTSCORE #
# Initialize with default parameters
cnts = CNTS(oracle, predictions) #This is how you initialize. trust_spectrum = True will save trust spectrum to the directory under "trust_spectrum.png" and "conditional_trust_densities.png"
cnts_scores_dict = cnts.compute() # Computes trustworthiness for each class and overall.
print(cnts_scores_dict)

Example Plot for Trust Spectrum (trust_spectrum = True) Alt text

Example Plot for Conditional Trust Spectrum (trust_spectrum = True) Alt text

I shared the codes for the plots Python scripts for plots for users to modify as needed.

This code was developed as a part of my publications listed below:

  1. Yanik, E., Kruger, U., Intes, X., Rahul, R., & De, S. (2023). Video-based formative and summative assessment of surgical tasks using deep learning. Scientific Reports, 13(1), 1038.
  2. Yanik, E., Ainam, J. P., Fu, Y., Schwaitzberg, S., Cavuoto, L., & De, S. (2024). Video-based skill acquisition assessment in laparoscopic surgery using deep learning. Global Surgical Education-Journal of the Association for Surgical Education, 3(1), 26.
  3. Yanik, E., Schwaitzberg, S., Yang, G., Intes, X., Norfleet, J., Hackett, M., & De, S. (2024). One-shot skill assessment in high-stakes domains with limited data via meta learning. Computers in Biology and Medicine, 174, 108470. / Yanik, E., Schwaitzberg, S., Yang, J., Intes, X., & De, S. (2022). One-shot domain adaptation in video-based assessment of surgical skills. arXiv e-prints, arXiv-2301.
  4. Yanik, E., Intes, X., & De, S. (2024). Cognitive-Motor Integration in Assessing Bimanual Motor Skills. arXiv preprint arXiv:2404.10889.

Licence

This project is licensed under the MIT License. See the file for details.

References for the methods:

1.How Much Can We Really Trust You? Towards Simple, Interpretable Trust Quantification Metrics for Deep Neural Networks.
2.Where Does Trust Break Down? A Quantitative Trust Analysis of Deep Neural Networks via Trust Matrix and Conditional Trust Densities.

If you use this package in your research, please cite the following papers accordingly:

For NTS:
@article{wong2020much,
  title={How much can we really trust you? towards simple, interpretable trust quantification metrics for deep neural networks},
  author={Wong, Alexander and Wang, Xiao Yu and Hryniowski, Andrew},
  journal={arXiv preprint arXiv:2009.05835},
  year={2020}
}

For conditional NTS:
@article{hryniowski2020does,
  title={Where does trust break down? A quantitative trust analysis of deep neural networks via trust matrix and conditional trust densities},
  author={Hryniowski, Andrew and Wang, Xiao Yu and Wong, Alexander},
  journal={arXiv preprint arXiv:2009.14701},
  year={2020}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trustpy_tools-2.0.3.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

trustpy_tools-2.0.3-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file trustpy_tools-2.0.3.tar.gz.

File metadata

  • Download URL: trustpy_tools-2.0.3.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.8

File hashes

Hashes for trustpy_tools-2.0.3.tar.gz
Algorithm Hash digest
SHA256 c9fccfacd4450b2e8a33b77d91ec56055c1092e058add7be0fa1060b34b356ec
MD5 2db9bb3754ac44d6f2c6aec56d020a92
BLAKE2b-256 abe02ae9757588cd1c56bcb26bd8a402a3940a62ca7824948ff73e4ac5c37c71

See more details on using hashes here.

File details

Details for the file trustpy_tools-2.0.3-py3-none-any.whl.

File metadata

  • Download URL: trustpy_tools-2.0.3-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.8

File hashes

Hashes for trustpy_tools-2.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2593a34d1f6e7838d015a07c59df1ef647410547adf48d45bfde92d1c2c4d6af
MD5 f5ba4553f6c908ab323ebd5243b0a3f7
BLAKE2b-256 4d0167dc28d1a40395858729c368892a6893a822c61b8f6dd78ecb0b634df2ad

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page