简体   繁体   中英

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? 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). In the case of GaussianNB the docs say that its score method:

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:

If False, return the number of correctly classified samples. 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.

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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