sklearn中score和accuracy_score的区别 [英] Difference between score and accuracy_score in sklearn
问题描述
sklearn.naive_bayes.GaussianNB()
模块中的 score()
方法和 sklearn 中的
模块?两者似乎是一样的.对吗?accuracy_score
方法有什么区别.指标
Whats the difference between score()
method in sklearn.naive_bayes.GaussianNB()
module and accuracy_score
method in sklearn.metrics
module? Both appears to be same. Is that correct?
推荐答案
通常,不同的模型具有返回不同指标的评分方法.这是为了允许分类器指定他们认为最适合他们的评分指标(例如,最小二乘回归分类器将有一个 score
方法,该方法返回类似于平方误差总和的内容).在 GaussianNB
的情况下,文档说它的评分方法:
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). In the case of GaussianNB
the docs say that its score method:
返回给定测试数据和标签的平均准确率.
Returns the mean accuracy on the given test data and labels.
accuracy_score
方法说它的返回值取决于 normalize
参数的设置:
The accuracy_score
method says its return value depends on the setting for the normalize
parameter:
如果为False,则返回正确分类的样本数.否则,返回正确分类样本的分数.
If False, return the number of correctly classified samples. Otherwise, return the fraction of correctly classified samples.
所以在我看来,如果您将 normalize
设置为 True
,您将获得与 GaussianNB.score
方法相同的值.
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
和 accuracy_score
调用 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. Do they?
这篇关于sklearn中score和accuracy_score的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!