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
Citation
The methodology is described in detail in:
[1] J. S. Aguilar-Ruiz and A. García Conde, “”
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file serendipity_matrix-1.0.0.tar.gz.
File metadata
- Download URL: serendipity_matrix-1.0.0.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95e9b99346e8bba5068c1f8b8f97288165be3e430eaca06c0f0d6bb3b7647ba8
|
|
| MD5 |
5357f3b3bed8041e01e81a86f061ad9e
|
|
| BLAKE2b-256 |
b0e72cb5624bf0d4a296564967aa0a39c7a6b48fa88c8b28f7e0cd65a4513050
|
File details
Details for the file serendipity_matrix-1.0.0-py3-none-any.whl.
File metadata
- Download URL: serendipity_matrix-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8a40ebf0543faf1613f15d6364f532b4da38f2331f66398b47c3ac24a8702e4
|
|
| MD5 |
c9dbb02557eb9a8c330cef377cd83b46
|
|
| BLAKE2b-256 |
4db17b0d0b7b90a7d3db7b0de34051e26ee29996aece7314f5c7f2a1d48c45df
|