user3053089 user3053089 - 5 months ago 45
Python Question

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.

Answer

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

from sklearn.metric 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