scanpy.metrics.confusion_matrix

scanpy.metrics.confusion_matrix#

scanpy.metrics.confusion_matrix(orig, new, data=None, *, normalize=True)[source]#

Given an original and new set of labels, create a labelled confusion matrix.

Parameters orig and new can either be entries in data or categorical arrays of the same size.

Parameters:
orig Series | ndarray | Sequence

Original labels.

new Series | ndarray | Sequence

New labels.

data DataFrame | None (default: None)

Optional dataframe to fill entries from.

normalize bool (default: True)

Should the confusion matrix be normalized?

Return type:

DataFrame

Examples

import scanpy as sc; import seaborn as sns
pbmc = sc.datasets.pbmc68k_reduced()
cmtx = sc.metrics.confusion_matrix("bulk_labels", "louvain", pbmc.obs)
sns.heatmap(cmtx)
<Axes: xlabel='louvain', ylabel='bulk_labels'>
../../_images/0a34e75145a87e329e15b69af4ec2f811fbe86ed2c2e7c036a64326b30783265.png