python - 在 python 中打印混淆矩阵的精度

标签 python scikit-learn

这是我的代码:

from sklearn.metrics import confusion_matrix

cm = confusion_matrix(y_test, y_pred)

这就是我得到的。

       0    1
 0  [[102  39]
 1   [ 73  29]]

我怎样才能打印分数29/(29+39),这意味着我的混淆矩阵的精度?

最佳答案

您需要的是 classification report来自 sklearn .

据说它返回:

Text summary of the precision, recall, F1 score for each class.

这是一个例子:

from sklearn.metrics import classification_report
y_true = [0, 1, 0, 1, 0]
y_pred = [0, 0, 1, 1, 1]
target =["yes", "no"]
print(classification_report(y_true, y_pred, target_names=target))

和输出:

enter image description here

关于python - 在 python 中打印混淆矩阵的精度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47792803/

相关文章:

python - 为什么循环末尾的数字打印两次

python - 如何使用训练好的文本分类模型

python - scikit-learn 中处理 nan/null 的分类器

python - 如何在 scikit-learn 的 LogisticRegressionCV 调用中将参数传递给评分函数

scikit-learn - scikit-learn 的 cross_val_score 中的 'score' 是什么意思?是否意味着准确?

python - 属性错误: module "sklearn.utils" has no attribute "_joblib" when inheriting class `sklearn.ensemble.BaggingClassifier.`

python - 在 Pandas Dataframe 中显示多列,但分组并仅计算一列

python - sklearn 维度问题 "Found array with dim 3. Estimator expected <= 2"

Python列出错误: localvars

python - 用 Python 从 3D 到 2D