Skip to content

Instantly share code, notes, and snippets.

Created September 9, 2020 20:08
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Plot a confusion matrix in scikitlearn from data not from an estimator
# This uses scikit learn internals, since the sk public API requires you to pass
# in an estimator and sometimes you just want to pass in the some data you'd
# use to calculate a raw CM
def plot_cm(y_true,y_pred,labels):
from sklearn.metrics._plot.confusion_matrix import ConfusionMatrixDisplay
sample_weight = None
normalize = None
include_values = True
ax = None
values_format = None
cm = confusion_matrix(y_true, y_pred, sample_weight=sample_weight,
labels=labels, normalize=normalize)
display_labels = labels
disp = ConfusionMatrixDisplay(confusion_matrix=cm,
return disp.plot(include_values=include_values,
cmap=cmap, ax=ax, xticks_rotation=xticks_rotation,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment