简体   繁体   中英

ImportError: No module named sklearn.preprocessing

I installed scikit-learn successfully on Ubuntu following these instructions .

However, I get this error when I run a program that uses it:

Traceback (most recent call last):
  File "begueradj.py", line 10, in <module>
    from sklearn.preprocessing import normalize
ImportError: No module named sklearn.preprocessing

How do I fix this?

The instructions given in that tutorial you linked to are obsolete for Ubuntu 14.04.

The Ubuntu 14.04 package is named python-sklearn (formerly python-scikits-learn ):

sudo apt-get install python-sklearn  

The python-sklearn package is in the default repositories in Ubuntu 14.04 as well as in other currently supported Ubuntu releases.

我通过在终端中运行这个命令解决了这个问题:

sudo apt-get install python-sklearn  

normalize is a method of Preprocessing. Therefore you need to import preprocessing.

In your code you can then call the method preprocessing.normalize().

from sklearn import preprocessing
preprocessing.normailze(x,y,z)

If you are looking to make the code short hand then you could use the import x from y as z syntax

from sklearn import preprocessing as prep
prep.normalize(x,y,z) 

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