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 trustpy-tools is via Conda-Forge, which handles all dependencies automatically. Run the following command:

conda install -c conda-forge trustpy-tools

Recommended 2: Install via PyPI (pip install)

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

pip install trustpy-tools

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/TrustPy.git
cd TrustPy

Example Usage

from trustpy 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.

Licence

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

References for the methods so far:

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.4.tar.gz (8.6 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.4-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: trustpy_tools-2.0.4.tar.gz
  • Upload date:
  • Size: 8.6 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.4.tar.gz
Algorithm Hash digest
SHA256 66bb5a03dc63badc9ab2abbbb86657e513d9a8b809772461d7712e56dbe0a48b
MD5 84aa564791d56d2fe93f128c34bd6aaf
BLAKE2b-256 83d0cd1cd31c7f329cf243a6f8ef8baea9374a165e2dab734586611f496af1e9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: trustpy_tools-2.0.4-py3-none-any.whl
  • Upload date:
  • Size: 9.0 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4e372980ba639edead32153aa24c93d814cd71b49eb242683d36971dd74d5fb4
MD5 330d04ea7448be346a2290171a6d02b8
BLAKE2b-256 eba5907274d50d2f7ed893dbdcd652202efceeb997c0e766e9618a5c03567b8e

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