Skip to main content

Serendipity Matrix

Project description

Serendipity Matrix

The package provides the methods to provide the serendipity matrix and for visualizing the serendipity matrix in a horizontal bar chart. The serendipity matrix is an innovative method to understand the behavior of a prediction model for classification problems.

This matrix provides information about the degree of certainty that the classifier has in its own predictions, indicating whether it is robust and reliable or uncertain and doubtful. This method has two variants: the class-independent serendipity matrix and the class-specific serendipity matrix depending on the kind of analysis required.

By analyzing the data provided by them, our goal is to improve the reliability and explainability of prediction models and to provide users with a clearer understanding of why a model is certain or uncertain about its predictions.

Installation

Serendipity Matrix can be installed from PyPI

pip install serendipity_matrix

Or you can clone the repository and run:

pip install .

Sample usage

from serendipity_matrix import class_indep_matrix, class_spec_matrix, plot_class_spec
from sklearn.naive_bayes import GaussianNB
from ucimlrepo import fetch_ucirepo

# Loads the dataset
wine_quality  = fetch_ucirepo(id=186) 
X, y = wine_quality.data.features, wine_quality.data.targets.squeeze()

# Training and predict
model = GaussianNB().fit(X, y)
result = model.predict_proba(X)

# Calculates and prints the class-independent serendipity matrix
ci_matrix = class_indep_matrix(y, result)
print(ci_matrix)

# Calculates and prints the class-specific serendipity matrix
cs_matrix = class_spec_matrix(y, result)
print(cs_matrix)

# Plots the class-specific serendipity matrix
plot_class_spec(y, result)

Result sample

Class-independent serendipity matrix

Reliability Overconfidence Underconfidence Serendipity
0.26401 0.29623 0.318717 0.021864

Class-specific serendipity matrix

CLASS_NAME Reliability Overconfidence Underconfidence Serendipity
3 0.072567 0.493307 0.412262 0.021864
4 0.054267 0.310598 0.597766 0.037369
5 0.383453 0.308486 0.198692 0.109368
6 0.272532 0.264399 0.267862 0.195207
7 0.227578 0.400299 0.308644 0.063479
8 0.010690 0.017746 0.902782 0.068782
9 0.031477 0.137502 0.822256 0.008765

Class-specific serendipity matrix horizontal bar chart

Class-specific serendipity matrix

Citation

The methodology is described in detail in:

[1] J. S. Aguilar-Ruiz and A. García Conde, “”

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

serendipity_matrix-1.0.1.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

serendipity_matrix-1.0.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file serendipity_matrix-1.0.1.tar.gz.

File metadata

  • Download URL: serendipity_matrix-1.0.1.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.5

File hashes

Hashes for serendipity_matrix-1.0.1.tar.gz
Algorithm Hash digest
SHA256 2de825be50f1287efd06094a4c55ebf7a915c733a49220407ec0a07346068e9a
MD5 f626995bd5272926ea9cb483a196b6aa
BLAKE2b-256 7cdad7317e6e77979bdfc46f52fe86972e2e1dbb2b7053d7da46518daee9c9ca

See more details on using hashes here.

File details

Details for the file serendipity_matrix-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for serendipity_matrix-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c44f52d2067657311858e784839b9f0f91ced7ea98b72a1d7b9d533aed7bfe5b
MD5 dae38c8fc9f77221017110c806358d90
BLAKE2b-256 903590ebb20649144eecc92152d418698b9a8eaa6aaf40ca8ced426ee83ea8da

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