Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何确定混淆矩阵的方向?_Python_Plotly_Visualization_Confusion Matrix_Plotly Python - Fatal编程技术网

Python 如何确定混淆矩阵的方向?

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() 但由于某些原因,绘图方向错误,“从左下角开

我使用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()
但由于某些原因,绘图方向错误,“从左下角开始”,如下所示:

是否有任何方法可以使矩阵沿常规方向移动,并显示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()