Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adjust size of ConfusionMatrixDisplay (ScikitLearn)

How to set the size of the figure ploted by ScikitLearn's ConfusionMatrixDisplay?

import numpy as np
from sklearn.metrics import ConfusionMatrixDisplay, confusion_matrix
cm = confusion_matrix(np.arange(25), np.arange(25))
cmp = ConfusionMatrixDisplay(cm, display_labels=np.arange(25))
cmp.plot()

The code above shows this figure, which is too tight:

enter image description here

like image 875
Raphael Avatar asked Mar 04 '21 21:03

Raphael


People also ask

How do I change the color of the confusion matrix?

Blues): you can change a name in cmap=plt. cm. Blues as the color you want such as green, red, orange, etc.


1 Answers

You can send a matplotlib.axes object to the .plot method of sklearn.metrics.ConfusionMatrixDisplay. Set the size of the figure in matplotlib.pyplot.subplots first.

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)

enter image description here

like image 148
Raphael Avatar answered Oct 17 '22 13:10

Raphael