python-3.x - 将归一化混淆矩阵限制为小数点后 2 位

标签 python-3.x

我显示的归一化混淆矩阵如下:

[[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/

相关文章:

python - 使用 spaCy 标记已标记化的字符串

python - jinja2.exceptions.UndefinedError - 没有属性 'favicon.ico'

python-3.x - 如何在python中检查蓝牙设备的ping

python - Python zmq SUB 套接字未接收到 MQL5 Zmq PUB 套接字

python - 求金字塔/三角形中相邻数字的最大和时输出错误

python-3.x - Flask 中 init_app 函数的目的是什么?

python - 将数据框列中的相似行合并为一个

python - 多处理池不改变处理速度?

python - 关于使用类型注释时python3中的python递归导入

python - 在 Windows 中安装 Python-saml 包时出错