Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't import sklearn.metrics.accuracy_score

I have successfully installed sklearn. However, when I run sklearn.metrics.accuracy_score, it givies an error ImportError: No module named 'sklearn.metrics.accuracy_score'

sklearn version is 0.17

numpy version is 1.8.2

scipy version is 0.13.3

Btw I'm using python3. Thanks.

like image 390
user3053089 Avatar asked Dec 15 '22 09:12

user3053089


2 Answers

accuracy_score is a function, not a module, you have to import it from a module, thus

from sklearn.metrics import accuracy_score #works
print(accuracy_score([1, 1, 0], [1, 0, 1]))

gives

0.333333333333

as expected.

and not

import sklearn.metrics.accuracy_score #error
like image 105
lejlot Avatar answered Dec 27 '22 23:12

lejlot


from sklearn.metrics import accuracy_score

print(accuracy_score([1, 1, 0], [1, 0, 1]))

Note: it's metrics not metric

like image 43
Anshul Tiwari Avatar answered Dec 27 '22 23:12

Anshul Tiwari