Skip to main content

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, “”

Metadata

Release files for serendipity-matrix 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for serendipity-matrix 1.0.2
File Size Uploaded Provenance Actions
serendipity_matrix-1.0.2.tar.gz 6.6 kB Without provenance Details for serendipity_matrix-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for serendipity-matrix 1.0.2
File Interpreter ABI Platform Actions
serendipity_matrix-1.0.2-py3-none-any.whl Python 3 none any Details for serendipity_matrix-1.0.2-py3-none-any.whl

Total release size: 13.8 kB

Release files / serendipity_matrix-1.0.2.tar.gz

Download URL serendipity_matrix-1.0.2.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
59549e72f6f39473d97e5724d9fccfd99bf3080630a25b6c395a485c2e6404f0
BLAKE2b-256 checksum
How to use checksums
5a677427e15f600034c7b46d7d13944a73859b257ca09e9d2c964566442aa97f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.5

Release files / serendipity_matrix-1.0.2-py3-none-any.whl

Download URL serendipity_matrix-1.0.2-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f0291ce04a5325b72bbd8b08c6d0430e2c639e81ad2ee65554edde1ee0236384
BLAKE2b-256 checksum
How to use checksums
9f8e43ca2e1009768a2cfa208158a2c07134aa1244da96157ba24f2cda2a7e9a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.5

Security for serendipity-matrix 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page