cm = confusion_matrix(test_label, y_pred) # 画出混淆矩阵 plt.imshow(cm, cmap=plt.cm.Blues) # plt.title('Confusion matrix'){'a': 'Condenser blockage', 'b': 'Main shaft wear', 'c': 'refrigerant overcharge'} plt.colorbar() tick_marks = np.arange(len(['a', 'b', 'c'])) plt.xticks(tick_marks, ['Condenser blockage', 'Main shaft wear', 'refrigerant overcharge'], rotation=45) plt.yticks(tick_marks, ['Condenser blockage', 'Main shaft wear', 'refrigerant overcharge']) plt.xlabel('Predicted label') plt.ylabel('True label') plt.tight_layout() plt.show(),帮我在这个混淆矩阵中加入数字
时间: 2023-08-04 15:08:12 浏览: 147
好的,您可以使用以下代码将数字添加到混淆矩阵中:
```python
cm = confusion_matrix(test_label, y_pred)
plt.imshow(cm, cmap=plt.cm.Blues)
# plt.title('Confusion matrix')
plt.colorbar()
tick_marks = np.arange(len(['a', 'b', 'c']))
plt.xticks(tick_marks, ['Condenser blockage', 'Main shaft wear', 'refrigerant overcharge'], rotation=45)
plt.yticks(tick_marks, ['Condenser blockage', 'Main shaft wear', 'refrigerant overcharge'])
thresh = cm.max() / 2.
for i, j in itertools.product(range(cm.shape[0]), range(cm.shape[1])):
plt.text(j, i, format(cm[i, j], 'd'),
horizontalalignment="center",
color="white" if cm[i, j] > thresh else "black")
plt.xlabel('Predicted label')
plt.ylabel('True label')
plt.tight_layout()
plt.show()
```
这将在混淆矩阵中的每个方格中心添加相应的数字。
阅读全文