【发布时间】:2020-10-24 14:12:09
【问题描述】:
我正在寻找可以帮助我绘制我的混淆矩阵的人。我在大学的学期论文需要这个。但是我的编程经验很少。
在图片中,您可以看到分类报告以及我的y_test 和X_test 的结构,在我的情况下为dtree_predictions。
如果有人可以帮助我,我会很高兴,因为我尝试了很多东西,但我没有得到解决方案,只有错误消息。
X_train, X_test, y_train, y_test = train_test_split(X, Y_profile, test_size = 0.3, random_state = 30)
dtree_model = DecisionTreeClassifier().fit(X_train,y_train)
dtree_predictions = dtree_model.predict(X_test)
print(metrics.classification_report(dtree_predictions, y_test))
precision recall f1-score support
0 1.00 1.00 1.00 222
1 1.00 1.00 1.00 211
2 1.00 1.00 1.00 229
3 0.96 0.97 0.96 348
4 0.89 0.85 0.87 93
5 0.86 0.86 0.86 105
6 0.94 0.93 0.94 116
7 1.00 1.00 1.00 364
8 0.99 0.97 0.98 139
9 0.98 0.99 0.99 159
10 0.97 0.96 0.97 189
11 0.92 0.92 0.92 124
12 0.92 0.92 0.92 119
13 0.95 0.96 0.95 230
14 0.98 0.96 0.97 452
15 0.91 0.96 0.93 210
micro avg 0.96 0.96 0.96 3310
macro avg 0.95 0.95 0.95 3310
weighted avg 0.97 0.96 0.96 3310
samples avg 0.96 0.96 0.96 3310
接下来我打印多标签混淆矩阵的度量
from sklearn.metrics import multilabel_confusion_matrix
multilabel_confusion_matrix(y_test, dtree_predictions)
array([[[440, 0],
[ 0, 222]],
[[451, 0],
[ 0, 211]],
[[433, 0],
[ 0, 229]],
[[299, 10],
[ 15, 338]],
[[559, 14],
[ 10, 79]],
[[542, 15],
[ 15, 90]],
[[539, 8],
[ 7, 108]],
[[297, 0],
[ 1, 364]],
[[522, 4],
[ 1, 135]],
[[500, 1],
[ 3, 158]],
[[468, 8],
[ 5, 181]],
[[528, 10],
[ 10, 114]],
[[534, 9],
[ 9, 110]],
[[420, 9],
[ 12, 221]],
[[201, 19],
[ 9, 433]],
[[433, 9],
[ 19, 201]]])
以及y_test和dtree_predictons的结构
print(dtree_predictions)
print(dtree_predictions.shape)
[[0. 0. 1. ... 0. 1. 0.]
[1. 0. 0. ... 0. 1. 0.]
[0. 0. 1. ... 0. 1. 0.]
...
[1. 0. 0. ... 0. 0. 1.]
[0. 1. 0. ... 1. 0. 1.]
[0. 1. 0. ... 1. 0. 1.]]
(662, 16)
print(y_test)
Cooler close to failure Cooler reduced effiency Cooler full effiency \
1985 0.0 0.0 1.0
322 1.0 0.0 0.0
2017 0.0 0.0 1.0
1759 0.0 0.0 1.0
1602 0.0 0.0 1.0
... ... ... ...
128 1.0 0.0 0.0
321 1.0 0.0 0.0
53 1.0 0.0 0.0
859 0.0 1.0 0.0
835 0.0 1.0 0.0
valve optimal valve small lag valve severe lag \
1985 0.0 0.0 0.0
322 0.0 1.0 0.0
2017 1.0 0.0 0.0
1759 0.0 0.0 0.0
1602 1.0 0.0 0.0
... ... ... ...
128 1.0 0.0 0.0
321 0.0 1.0 0.0
53 1.0 0.0 0.0
859 1.0 0.0 0.0
835 1.0 0.0 0.0
valve close to failure pump no leakage pump weak leakage \
1985 1.0 0.0 1.0
322 0.0 1.0 0.0
2017 0.0 0.0 1.0
1759 1.0 1.0 0.0
1602 0.0 1.0 0.0
... ... ... ...
128 0.0 1.0 0.0
321 0.0 1.0 0.0
53 0.0 1.0 0.0
859 0.0 1.0 0.0
835 0.0 1.0 0.0
pump severe leakage accu optimal pressure \
1985 0.0 0.0
322 0.0 1.0
2017 0.0 0.0
1759 0.0 1.0
1602 0.0 0.0
... ... ...
128 0.0 1.0
321 0.0 1.0
53 0.0 1.0
859 0.0 0.0
835 0.0 0.0
accu slightly reduced pressure accu severly reduced pressure \
1985 0.0 1.0
322 0.0 0.0
2017 0.0 1.0
1759 0.0 0.0
1602 0.0 0.0
... ... ...
128 0.0 0.0
321 0.0 0.0
53 0.0 0.0
859 0.0 0.0
835 0.0 0.0
accu close to failure stable flag stable stable flag not stable
1985 0.0 1.0 0.0
322 0.0 1.0 0.0
2017 0.0 1.0 0.0
1759 0.0 1.0 0.0
1602 1.0 0.0 1.0
... ... ... ...
128 0.0 0.0 1.0
321 0.0 1.0 0.0
53 0.0 0.0 1.0
859 1.0 0.0 1.0
835 1.0 0.0 1.0
[662 rows x 16 columns]
【问题讨论】:
-
请将您的代码添加为文本,以便回答者可以重现您的输出并为您提供帮助
-
我有一个问题是从头开始的整个代码还是只有图片的代码?
-
如果合理,您应该尽可能多地发布您的代码。另外,不要超链接到您的代码图像,而是将您的代码发布为格式化文本,以便想要帮助您的人可以复制和粘贴它并尝试自己运行它
-
好的。谢谢你。我添加了一些信息。
-
当你在帮助或谷歌上搜索“plot/get Confusion Matrix”时,你发现了什么命令?请发布您的实际代码。我想你不想要情节,你只想要一张桌子?请确认。此外,您需要标记此python,以便人们知道您使用的是什么语言,然后将其分发给该标记中的数千名用户。
标签: python scikit-learn decision-tree confusion-matrix multilabel-classification