如何找出准确度? [英] How to find out the accuracy?

查看:67
本文介绍了如何找出准确度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道 sklearn 中是否有对应于准确度(实际数据和预测数据之间的差异)以及如何打印出来的函数?

I've wondered if there is a function in sklearn which corresponds to the accuracy(difference between actual and predicted data) and how to print it out?

from sklearn import datasets 
iris = datasets.load_iris()
from sklearn.naive_bayes import GaussianNB
naive_classifier= GaussianNB()
y =naive_classifier.fit(iris.data, iris.target).predict(iris.data)
pr=naive_classifier.predict(iris.data)

推荐答案

scikit 中的大多数分类器都有一个内置的 score() 函数,您可以在其中输入 X_test 和 y_test,它将输出适当的度量那个估计.对于分类估计器,它主要是'平均准确度'.

Most classifiers in scikit have an inbuilt score() function, in which you can input your X_test and y_test and it will output the appropriate metric for that estimator. For classification estimators it is mostly 'mean accuracy'.

还有 sklearn.metrics 有许多可用的函数可以输出不同的指标,例如 accuracyprecisionrecall 等.

对于您的具体问题,您需要accuracy_score

For your specific question you need accuracy_score

from sklearn.metrics import accuracy_score
score = accuracy_score(iris.target, pr)

这篇关于如何找出准确度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆