grassp.tl.annotation_confusion_matrix

grassp.tl.annotation_confusion_matrix#

annotation_confusion_matrix(data, gt_col, pred_col, soft=False, cluster=False, plot=True)[source]#

Confusion matrix of a predicted annotation against ground-truth labels.

Works for any annotator that stores a labelled probability matrix in obsm[f"{pred_col}_probabilities"].

Parameters:
data

AnnData object.

gt_col

Observation column with ground-truth labels.

pred_col

Annotation prefix: the labels are read from obs[pred_col] and the probabilities from obsm[f"{pred_col}_probabilities"].

soft default: False

If True, use probabilistic (soft) confusion matrix instead of hard assignments.

plot=True

If True, plot the heatmap of the confusion matrix, otherwise return the confusion matrix.

cluster default: False

If True, reorder matrix rows and columns via hierarchical clustering for visualization.

Returns:

None. Displays a heatmap of the confusion matrix if plot is True, otherwise returns the confusion matrix.