【发布时间】:2020-02-22 19:53:12
【问题描述】:
我正在使用 scikit 学习决策树将一组数据分类为四个类别之一。我一般是机器学习和编码的新手,并且正在尝试理解混淆矩阵。
所以当我使用 sci-kits 混淆矩阵时,我得到一个四乘四矩阵。我能够弄清楚这些列是对每个类别的预测(例如“预测 A,预测 B ...”)。但是,我对这些行代表什么感到困惑。此外,某些预测是否有可能不进入混淆矩阵。我发现某些列没有必要的总计数。这是为什么呢?
unique, counts = np.unique(classif_predict, return_counts=True)
print('Predicted:',dict(zip(unique, counts)))
_unique, _counts = np.unique(classif_test, return_counts=True)
print('Tested:',dict(zip(_unique, _counts)))
pd.DataFrame(
confusion_matrix(classif_test, class_predict),
columns = ['AGN Predicted', 'BeXRB Predicted', 'HMXB Predicted', 'SNR Predicted']
)
我的输出如下所示:
Predicted: {'AGN': 7, 'BeXRB': 25, 'HMXB': 7, 'SNR': 2}
Tested: {'AGN': 10, 'BeXRB': 22, 'HMXB': 7, 'SNR': 2}
AGN Predicted BeXRB Predicted HMXB Predicted SNR Predicted
3 3 4 0
2 13 6 1
0 3 4 0
0 2 0 0
```
【问题讨论】:
-
这在 Cross Validated 上可能会更好。
-
我在 Cross Validated 上将其标记为 Stack Exchange。你会在那里得到最好的答案。
标签: python scikit-learn confusion-matrix