获取等于 class 标签数量的多 class 混淆矩阵
Get multi-class confusion matrix equal to number of class labels
我在 sklearn
中训练了随机森林分类器来预测多 class class 化问题。
我的数据集有四个 class 标签。但是我的代码创建了 2x2 混淆矩阵
y_predict = rf.predict(X_test)
conf_mat = sklearn.metrics.confusion_matrix(y_test, y_predict)
print(conf_mat)
输出:
[[0, 0]
[394, 39]]
如何获得 4x4 混淆矩阵来分析 TP、TN、FP、FN。
来自
的文档
http://scikit-learn.org/stable/modules/generated/sklearn.metrics.confusion_matrix.html
y_true = ["cat", "ant", "cat", "cat", "ant", "bird"]
y_pred = ["ant", "ant", "cat", "cat", "ant", "cat"]
confusion_matrix(y_true, y_pred, labels=["ant", "bird", "cat"])
结果:
array([[2, 0, 0],
[0, 0, 1],
[1, 0, 2]])
我在 sklearn
中训练了随机森林分类器来预测多 class class 化问题。
我的数据集有四个 class 标签。但是我的代码创建了 2x2 混淆矩阵
y_predict = rf.predict(X_test)
conf_mat = sklearn.metrics.confusion_matrix(y_test, y_predict)
print(conf_mat)
输出:
[[0, 0]
[394, 39]]
如何获得 4x4 混淆矩阵来分析 TP、TN、FP、FN。
来自
的文档
http://scikit-learn.org/stable/modules/generated/sklearn.metrics.confusion_matrix.html
y_true = ["cat", "ant", "cat", "cat", "ant", "bird"]
y_pred = ["ant", "ant", "cat", "cat", "ant", "cat"]
confusion_matrix(y_true, y_pred, labels=["ant", "bird", "cat"])
结果:
array([[2, 0, 0],
[0, 0, 1],
[1, 0, 2]])