Skip to main content

Calculate common OOD detection metrics

Project description

OOD Detection Metrics

Functions for computing metrics commonly used in the field of out-of-distribution (OOD) detection.

Installation

pip install ood-metrics

Metrics functions

AUROC

Calculate and return the area under the ROC curve using unthresholded predictions on the data and a binary true label.

from ood_metrics import auroc

labels = [0, 0, 0, 1, 0]
scores = [0.1, 0.3, 0.6, 0.9, 1.3]

print(auroc(scores, labels))
# 0.75

AUPR

Calculate and return the area under the Precision Recall curve using unthresholded predictions on the data and a binary true label.

from ood_metrics import aupr

labels = [0, 0, 0, 1, 0]
scores = [0.1, 0.3, 0.6, 0.9, 1.3]

print(aupr(scores, labels))
# 0.25

FPR @ 95% TPR

Return the FPR when TPR is at least 95%.

from ood_metrics import fpr_at_95_tpr

labels = [0, 0, 0, 1, 0]
scores = [0.1, 0.3, 0.6, 0.9, 1.3]

print(fpr_at_95_tpr(scores, labels))
# 0.25

Detection Error

Return the misclassification probability when TPR is 95%.

from ood_metrics import detection_error

labels = [0, 0, 0, 1, 0]
scores = [0.1, 0.3, 0.6, 0.9, 1.3]

print(detection_error(scores, labels))
# 0.125

Calculate all stats

Using predictions and labels, return a dictionary containing all novelty detection performance statistics.

from ood_metrics import calc_metrics

labels = [0, 0, 0, 1, 0]
scores = [0.1, 0.3, 0.6, 0.9, 1.3]

print(calc_metrics(scores, labels))
# {
#     'fpr_at_95_tpr': 0.25,
#     'detection_error': 0.125,
#     'auroc': 0.75,
#     'aupr_in': 0.25,
#     'aupr_out': 0.94375
# }

Plotting functions

Plot ROC

Plot an ROC curve based on unthresholded predictions and true binary labels.

from ood_metrics import plot_roc

labels = [0, 0, 0, 1, 0]
scores = [0.1, 0.3, 0.6, 0.9, 1.3]

plot_roc(scores, labels)
# Generate Matplotlib AUROC plot

Plot PR

Plot an Precision-Recall curve based on unthresholded predictions and true binary labels.

from ood_metrics import plot_pr

labels = [0, 0, 0, 1, 0]
scores = [0.1, 0.3, 0.6, 0.9, 1.3]

plot_pr(scores, labels)
# Generate Matplotlib Precision-Recall plot

Plot Barcode

Plot a visualization showing inliers and outliers sorted by their prediction of novelty.

from ood_metrics import plot_barcode

labels = [0, 0, 0, 1, 0]
scores = [0.1, 0.3, 0.6, 0.9, 1.3]

plot_barcode(scores, labels)
# Shows visualization of sort order of labels occording to the scores.

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

ood-metrics-1.0.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

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

ood_metrics-1.0.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file ood-metrics-1.0.0.tar.gz.

File metadata

  • Download URL: ood-metrics-1.0.0.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.9.13 Linux/5.15.0-1017-azure

File hashes

Hashes for ood-metrics-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d9f400c8cbcf244bee80151b845a0defd9a9e12733f288e500a3f7dd9c5d721c
MD5 f9afeea6fd33616309f396d09bc53e28
BLAKE2b-256 51c8afa9a673f2f967264e72a026e53ed5aaec694876095f00a81796fd3bdb2c

See more details on using hashes here.

File details

Details for the file ood_metrics-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: ood_metrics-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.9.13 Linux/5.15.0-1017-azure

File hashes

Hashes for ood_metrics-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e28e3ffc619f3a5594cd16eb5a5a97eb11eae60d83537591b7310c81a0ac332a
MD5 c25e52292d9d54fe21c7bb4e7aff928c
BLAKE2b-256 1d4da0ed7c6b48fbc3f85fb20234a18135ff53257aec299c659dcc7ecceadb12

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