归一化后混淆矩阵怎么看
时间: 2024-05-07 08:14:49 浏览: 32
归一化后的混淆矩阵可以更好地说明分类器的表现,因为它显示了每个类别的分类准确率。在归一化混淆矩阵中,每个单元格代表分类器将一个样本正确分类的概率。因此,对角线上的数字表示分类器正确分类该类别的概率,而非绝对数量。非对角线上的数字表示分类器将一个类别错误分类为另一个类别的概率。通过观察归一化混淆矩阵,我们可以更好地了解分类器在不同类别上的表现,并且可以更好地比较不同分类器的性能。
相关问题
python如何实现混淆矩阵归一化
在Python中,可以使用scikit-learn库中的confusion_matrix函数来计算混淆矩阵。要将混淆矩阵归一化,可以将normalize参数设置为True。具体实现代码如下:
```
from sklearn.metrics import confusion_matrix
import matplotlib.pyplot as plt
# 计算混淆矩阵
cnf_matrix = confusion_matrix(y_true, y_pred)
# 归一化混淆矩阵
normalized_cnf_matrix = cnf_matrix.astype('float') / cnf_matrix.sum(axis=1)[:, np.newaxis]
# 绘制归一化混淆矩阵
plt.imshow(normalized_cnf_matrix, interpolation='nearest', cmap=plt.cm.Blues)
plt.title("Normalized Confusion Matrix")
plt.colorbar()
tick_marks = np.arange(len(classes))
plt.xticks(tick_marks, classes, rotation=45)
plt.yticks(tick_marks, classes)
plt.tight_layout()
plt.ylabel('True label')
plt.xlabel('Predicted label')
plt.show()
```
其中,y_true和y_pred分别是真实标签和预测标签,classes是类别列表。绘制出来的归一化混淆矩阵可以更直观地反映分类器的性能。
python中归一化混淆矩阵的计算公式
Python中可以使用sklearn.metrics中的confusion_matrix函数计算混淆矩阵,并使用sklearn.metrics中的normalize参数来计算归一化混淆矩阵。具体的计算公式如下:
设真实标签为y_true,预测标签为y_pred,其中y_true和y_pred都是长度为n的数组。
则混淆矩阵的四个元素分别为:
- TP(True Positive):y_true和y_pred都为正例
- FP(False Positive):y_true为负例,y_pred为正例
- FN(False Negative):y_true为正例,y_pred为负例
- TN(True Negative):y_true和y_pred都为负例
则混淆矩阵的计算公式为:
![confusion_matrix](https://cdn.jsdelivr.net/gh/zyangmath/zyangmath-image-repo/img/confusion_matrix.png)
其中,归一化混淆矩阵的计算公式为:
![normalized_confusion_matrix](https://cdn.jsdelivr.net/gh/zyangmath/zyangmath-image-repo/img/normalized_confusion_matrix.png)
其中,N为样本总数。在sklearn中,可以通过设置normalize参数来计算归一化混淆矩阵,其取值可以为'all'或'true'。当normalize='all'时,计算的是所有样本的归一化混淆矩阵;当normalize='true'时,计算的是每一行的归一化混淆矩阵。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)