Python 3.x 将标准化混淆矩阵限制为2个小数点

Python 3.x 将标准化混淆矩阵限制为2个小数点,python-3.x,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.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)