Skip to main content

Plot Confusion Matrix in Python

Plot a pretty confusion matrix (like Matlab) in python using seaborn and matplotlib

This module lets you plot a pretty looking confusion matrix from a np matrix or from a prediction results and actual labels.

Example plot:

alt text

Getting started

Installation

pip install confplot

Usage

Plot confusion matrix from matrix

# import package
import confplot

# assume you have a confusion matrix array like this
array = np.array(
    [[13,  0,  1,  0,  2,  0],
     [ 0, 50,  2,  0, 10,  0],
     [ 0, 13, 16,  0,  0,  3],
     [ 0,  0,  0, 13,  1,  0],
     [ 0, 40,  0,  1, 15,  0],
     [ 0,  0,  0,  0,  0, 20]]
)

# convert it to a pandas dataframe
df_cm = DataFrame(array, index=range(1, 7), columns=range(1, 7))

# create and save confusion matrix plot as "cm_plot.png"
confplot.plot_confusion_matrix_from_matrix(df_cm, outfule="cm_plot.png")

Plot confusion matrix from data

# import package
import confplot

# assume you have 1D y_true (actual values) and y_pred (predictions) arrays
y_true = ...
y_pred = ...

# arange targetclass names if you want
columns = ["ahududu", "ananas", "armut", "avokado", "ayva"]

# create and save confusion matrix plot as "cm_plot.png"
confplot.plot_confusion_matrix_from_data(
    y_true,
    y_pred,
    columns,
    outfule="cm_plot.png"
)

Metadata

Release files for confplot 0.1.0

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

Source distribution (sdist)

Source distribution for confplot 0.1.0
File Size Uploaded
confplot-0.1.0.tar.gz 6.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for confplot 0.1.0
File Interpreter ABI Platform
confplot-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.8 kB

Release files / confplot-0.1.0.tar.gz

Download URL confplot-0.1.0.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4475c42aa57e4ce566f066ace8e14de105d8e2af5c122cfee673a75e7f33ecd7
BLAKE2b-256 checksum
How to use checksums
4d6b2258e7be4ab959089533f608a4a3acfd5cc2916599d42ee079cc6681f49e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

Release files / confplot-0.1.0-py3-none-any.whl

Download URL confplot-0.1.0-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
57cfe615f111ba36a7b45ea2a0a9207ee472cfc6526c2ceed7aad37788546204
BLAKE2b-256 checksum
How to use checksums
63ddc65582eebf689dc332189d14821be6f42900c95dc7a55c79ec971a1d4fd1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

Release history Release notifications | RSS feed

0.1.1

2 release files

This release

0.1.0 This release

2 release files

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