从python中的混淆矩阵打印精度 [英] printing the precision from a confusion matrix in python
本文介绍了从python中的混淆矩阵打印精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
from sklearn.metrics 导入混淆_矩阵厘米 = 混淆矩阵(y_test,y_pred)
这就是我得到的.
<代码> 0 10 [[102 39]1 [ 73 29]]
我如何只打印分数 29/(29+39)
,这意味着我的混淆矩阵的精度?
解决方案
你需要的是
Here is my code:
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)
This is what I am getting.
0 1
0 [[102 39]
1 [ 73 29]]
How can I just print the fraction 29/(29+39)
, meaning the precision of my confusiin matrix?
解决方案
what you need is classification report from sklearn .
it's said that it returns:
Text summary of the precision, recall, F1 score for each class.
here is an example :
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))
and the output :
这篇关于从python中的混淆矩阵打印精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文