我显示的归一化混淆矩阵如下:
[[0.9 0. 0.0106383 0. 0. ]
[0. 0.83673469 0.05319149 0.01801802 0.04347826]
[0. 0.04081633 0.87234043 0.09009009 0. ]
[0. 0. 0.14893617 0.83783784 0.17391304]
[0. 0. 0.04255319 0.04504505 0.60869565]]
我只想显示小数点后两位。
这是我的归一化混淆矩阵的代码:
# Confusion Matrix
conf_mat = confusion_matrix(y_test, predicted)
conf_mat_norm = conf_mat / conf_mat.astype(np.float).sum(axis=1))
最佳答案
你可以使用这个方法,它对我有用。如果这个答案适合您,请投票。
conf_mat_norm= np.around(conf_mat.astype('float') / conf_mat.sum(axis=1)[:, np.newaxis], decimals=2)
关于python-3.x - 将归一化混淆矩阵限制为小数点后 2 位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59049746/