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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With