混淆矩阵绘制

编程入门 行业动态 更新时间:2024-10-26 02:36:04

混淆<a href=https://www.elefans.com/category/jswz/34/1769510.html style=矩阵绘制"/>

混淆矩阵绘制

import numpy as np
import matplotlib.pyplot as plt
from sklearn.metrics import confusion_matrix# 示例的真实标签和预测标签
true_labels = ['cat', 'dog', 'bird', 'cat', 'dog', 'bird', 'cat', 'bird', 'bird']
predicted_labels = ['cat', 'bird', 'dog', 'cat', 'bird', 'dog', 'cat', 'cat', 'bird']# 确定所有类别的唯一值
unique_labels = np.unique(true_labels)# 计算混淆矩阵
cm = confusion_matrix(true_labels, predicted_labels)
print(cm)
# 绘制混淆矩阵的可视化
plt.imshow(cm, interpolation='nearest', cmap=plt.cm.Blues)
plt.title('Confusion Matrix')
plt.colorbar()
tick_marks = np.arange(len(unique_labels))
plt.xticks(tick_marks, unique_labels)
plt.yticks(tick_marks, unique_labels)
plt.xlabel('Predicted Label')
plt.ylabel('True Label')
plt.show()

[[1 1 2]
[0 3 0]
[2 0 0]]

更多推荐

混淆矩阵绘制

本文发布于:2023-12-06 19:39:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1668626.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:矩阵

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!