Skip to main content

Trustworthiness metrics for Softmax predictive models

Project description

Trustworthiness Quantification

This repository provides a Python implementation of trustworthiness quantification metrics for predictive models (e.g., DNNs):

The implementation is flexible and works out-the-box with any Python code that outputs SoftMax probabilities.

Key Features

  • Question-Answer Trust: Computes trust scores per sample based on prediction correctness and softmax probability.
  • Trust Density: Estimates the distribution of trust scores per class using Kernel Density Estimation (KDE).
  • Trust Spectrum: Visualizes trust densities across all classes.
  • NetTrustScore (NTS): Provides a scalar metric summarizing overall trustworthiness.

Installation

Recommended: 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

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 pip:

pip install numpy matplotlib scikit-learn

or

Install them via conda:

conda 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

nettrustscore-2.0.2.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

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

nettrustscore-2.0.2-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file nettrustscore-2.0.2.tar.gz.

File metadata

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

File hashes

Hashes for nettrustscore-2.0.2.tar.gz
Algorithm Hash digest
SHA256 641d16dbc05aa01ab7ac65591446f286cb91178728cb90c4b364227642ae386d
MD5 37c804fb8d076f5cb585613243e5153c
BLAKE2b-256 95db4c38ecb3782322cd7a85b790a3210e3b03178ef560e26e10818942529a69

See more details on using hashes here.

File details

Details for the file nettrustscore-2.0.2-py3-none-any.whl.

File metadata

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

File hashes

Hashes for nettrustscore-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3bb0119285304a1eb6459d3d1e729654a4ea09cd1f73e52716a01795cf9827dd
MD5 4cc2cc7c22b9e4af5e5e27eed983ca4b
BLAKE2b-256 b3a07ce0ca1dcbbb8fc022802900ce7fa836a0c61e5c1d4dfdc915c4407be999

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