首页 > 解决方案 > Confusion matrix layout in python

问题描述

I have made a confusion matrix using the code here:

https://scikit-learn.org/stable/auto_examples/model_selection/plot_confusion_matrix.html#sphx-glr-auto-examples-model-selection-plot-confusion-matrix-py

Confusion matrix result

How can I change the layout so that I can see all the numbers in the first and last row without them being cut off?

Thank you!

标签: pythonconfusion-matrix

解决方案


You need to add some padding to the axes by setting the axis ticks like this:

ax.set_xticks(np.arange(cm.shape[1]+1)-.5)
ax.set_yticks(np.arange(cm.shape[0]+1)-.5)

Here is similer matplotlib example.


推荐阅读