Python 如何确定混淆矩阵的方向?
我使用Plotly绘制以下混淆矩阵:Python 如何确定混淆矩阵的方向?,python,plotly,visualization,confusion-matrix,plotly-python,Python,Plotly,Visualization,Confusion Matrix,Plotly Python,我使用Plotly绘制以下混淆矩阵: cf_matrix= confusion_matrix(y_true, y_pred) print(cf_matrix) [[1595 545 2240] [ 788 722 2870] [ 181 118 4081]] import plotly.figure_factory as ff fig = ff.create_annotated_heatmap(cf_matrix) fig.show() 但由于某些原因,绘图方向错误,“从左下角开
cf_matrix= confusion_matrix(y_true, y_pred)
print(cf_matrix)
[[1595 545 2240]
[ 788 722 2870]
[ 181 118 4081]]
import plotly.figure_factory as ff
fig = ff.create_annotated_heatmap(cf_matrix)
fig.show()
但由于某些原因,绘图方向错误,“从左下角开始”,如下所示:
是否有任何方法可以使矩阵沿常规方向移动,并显示X轴和Y轴?答案:
您的示例中的一些详细信息:
如果您提供的数据实际上是您的数据集,那么您没有指定任何名称。例如,您可以使用names=list('ABC')
,然后执行以下操作:
fig = ff.create_annotated_heatmap(z, x = names, y = names)
要更改热图的顺序,可以执行以下操作:
fig.update_layout(yaxis = dict(categoryorder = 'category descending'))
绘图:
如果这不是您想要的显示方式,您可以用相同的方式更改xaxis
。此外,categoryorder的其他选项包括:
['trace', 'category ascending', 'category descending',
'array', 'total ascending', 'total descending', 'min
ascending', 'min descending', 'max ascending', 'max
descending', 'sum ascending', 'sum descending', 'mean
ascending', 'mean descending', 'median ascending', 'median
descending']
完整代码:
非凡的非常感谢维斯特兰:)@MohammadAlshehri不客气!你能把我的建议看作是公认的答案吗?
['trace', 'category ascending', 'category descending',
'array', 'total ascending', 'total descending', 'min
ascending', 'min descending', 'max ascending', 'max
descending', 'sum ascending', 'sum descending', 'mean
ascending', 'mean descending', 'median ascending', 'median
descending']
import plotly.figure_factory as ff
z = [[1595, 545, 2240],
[ 788, 722, 2870],
[ 181, 118, 4081]]
names = list('ABC')
fig = ff.create_annotated_heatmap(z, x = names, y = names)
fig.update_layout(yaxis = dict(categoryorder = 'category descending'))
fig.show()