caret-style confusion matrices and classification statistics for Python
Project description
caretmetrics
caret-style confusion matrices and classification statistics for Python.
Reproduces the output of R's caret::confusionMatrix() — same table
orientation (Prediction in rows, Reference in columns), a chosen
positive class, the exact (Clopper–Pearson) 95% CI, the Acc > NIR
binomial test, McNemar's test, and Cohen's Kappa.
Install (local, editable)
From the project folder:
pip install -e .
This installs the package in "editable" mode, so edits to the source take effect immediately without reinstalling.
Usage
import pandas as pd
from caretmetrics import confusion_matrix
df = pd.read_excel("data.xlsx")
cm = confusion_matrix(df["survived"], df["pred_classes"], positive="yes")
print(cm) # caret-style report
cm.accuracy # 0.774...
cm.kappa # 0.528...
cm.as_dict() # all statistics as a dict
cm.table # 2x2 numpy array (rows=Prediction, cols=Reference)
Notes
- Positive class is explicit; flipping it swaps sensitivity/specificity and the predictive values.
- Orientation is the opposite of
sklearn.metrics.confusion_matrix, which is the usual reason Python and R matrices don't line up.
Test
pip install -e ".[dev]"
pytest
License
MIT
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 caretmetrics-0.1.0.tar.gz.
File metadata
- Download URL: caretmetrics-0.1.0.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e54eee62b4605b075a3edfee4d098d93ea350220bcad640b7ac6c8b1ad43e18
|
|
| MD5 |
0bb5e62274aecf6e2804d38c20151d46
|
|
| BLAKE2b-256 |
888071b7e1cf6cef3bd7500ef217a68393600cbfb42af8e45adba1dd802e93b7
|
File details
Details for the file caretmetrics-0.1.0-py3-none-any.whl.
File metadata
- Download URL: caretmetrics-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3bd800827637c52d2a1d5f1957733f3c8f47610c34255cf336b0ae84d6dc13d
|
|
| MD5 |
7c4a9e6716ac67ab3c9b6281ceddcc7f
|
|
| BLAKE2b-256 |
78529a9e78bdba686f2c93ae1e972d8e82613fc378b4b4746b18c8a613c6930d
|