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.2.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.2-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: serendipity_matrix-1.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 59549e72f6f39473d97e5724d9fccfd99bf3080630a25b6c395a485c2e6404f0
MD5 f96d08d8ad0508d7cb607746ae91c744
BLAKE2b-256 5a677427e15f600034c7b46d7d13944a73859b257ca09e9d2c964566442aa97f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for serendipity_matrix-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f0291ce04a5325b72bbd8b08c6d0430e2c639e81ad2ee65554edde1ee0236384
MD5 f7d8e8493543df07264842c2481690e2
BLAKE2b-256 9f8e43ca2e1009768a2cfa208158a2c07134aa1244da96157ba24f2cda2a7e9a

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