Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 421
A.R Naseef Avatar asked Nov 21 '16 18:11

A.R Naseef


1 Answers

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?

like image 115
Oliver Dain Avatar answered Oct 14 '22 04:10

Oliver Dain