ConfusionMatrixDisplay
docs say:
It is recommend to use
from_estimator
orfrom_predictions
to create a ConfusionMatrixDisplay.
However, I want to plot the matrix manually on some axes I configure, and when I use from_predictions
, I can't prevent it from plotting the matrix. The result is that I get two plots shown: one from the from_predictions
call, and one from cmp.plot()
.
For example, this results in two plots:
import numpy as np
from sklearn.metrics import ConfusionMatrixDisplay, confusion_matrix
import matplotlib.pyplot as plt
cmp = ConfusionMatrixDisplay.from_predictions(np.arange(25), np.arange(25))
fig, ax = plt.subplots(figsize=(10,10))
cmp.plot(ax=ax)
But this results in one:
import numpy as np
from sklearn.metrics import ConfusionMatrixDisplay, confusion_matrix
import matplotlib.pyplot as plt
cm = confusion_matrix(np.arange(25), np.arange(25))
cmp = ConfusionMatrixDisplay(cm, display_labels=np.arange(25))
fig, ax = plt.subplots(figsize=(10,10))
cmp.plot(ax=ax)
I would like to use from_predictions
, but to have it not plot, like using the constructor.
Notebook: https://drive.google.com/file/d/1lUPpp0dYfuIk1z8o7QfdUlQTt9eJ1dy4/view?usp=sharing