简体   繁体   中英

Python adjust scale intensity at confusion matrix plot

I have a number of confusion matrix plots with numbers not summing up to the same sum (the numbers are out of 100 for a benchmark) Please see attached example image below: confusion matrix I do not want the 22 and the 32 have the same color intensity, but be at the same scale from 0 to 100 intensity levels. How can I adjust the scale in python given the following used code:

import matplotlib.pyplot as plt
from sklearn.datasets import make_classification
from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay

cm = confusion_matrix(y_true, y_pred, labels=["Up", "Down"])
disp = ConfusionMatrixDisplay(confusion_matrix=cm,display_labels=["Up", "Down"])
disp.plot(cmap="OrRd")
disp.ax_.get_images()[0].set_clim(0, 100)

And the full code:

import matplotlib.pyplot as plt
from sklearn.datasets import make_classification
from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay

cm = confusion_matrix(y_true, y_pred, labels=["Up", "Down"])

disp = ConfusionMatrixDisplay(confusion_matrix=cm,display_labels=["Up", "Down"])
disp.plot(cmap="OrRd")

disp.ax_.get_images()[0].set_clim(0, 100)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM