简体   繁体   English

sklearn中score和accuracy_score的区别

[英]Difference between score and accuracy_score in sklearn

Whats the difference between score() method in sklearn.naive_bayes.GaussianNB() module and accuracy_score method in sklearn.metrics module? sklearn.naive_bayes.GaussianNB()模块中的score()方法和sklearn.naive_bayes.GaussianNB()模块中的accuracy_score方法有什么sklearn.metrics Both appears to be same.两者似乎是一样的。 Is that correct?那是正确的吗?

In general, different models have score methods that return different metrics.通常,不同的模型具有返回不同指标的评分方法。 This is to allow classifiers to specify what scoring metric they think is most appropriate for them (thus, for example, a least-squares regression classifier would have a score method that returns something like the sum of squared errors).这是为了允许分类器指定他们认为最适合他们的评分指标(例如,最小二乘回归分类器将有一个score方法,该方法返回类似于平方误差总和的内容)。 In the case of GaussianNB the docs say that its score method:GaussianNB的情况下,文档说它的评分方法:

Returns the mean accuracy on the given test data and labels.返回给定测试数据和标签的平均准确度。

The accuracy_score method says its return value depends on the setting for the normalize parameter: accuracy_score方法说它的返回值取决于normalize参数的设置:

If False, return the number of correctly classified samples.如果为 False,则返回正确分类的样本数。 Otherwise, return the fraction of correctly classified samples.否则,返回正确分类样本的分数。

So it would appear to me that if you set normalize to True you'd get the same value as the GaussianNB.score method.所以在我看来,如果您将normalize设置为True您将获得与GaussianNB.score方法相同的值。

One easy way to confirm my guess is to build a classifier and call both score with normalize = True and accuracy_score and see if they match.确认我的猜测的一种简单方法是构建一个分类器并使用normalize = Trueaccuracy_score调用这两个score并查看它们是否匹配。 Do they?他们吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM