-1

I entered the following code:

import sklearn
import sklearn as sk
import sklearn.preprocessing as skl

from sklearn.preprocessing import Imputer 
from sk.preprocessing import Imputer
from skl import Imputer

The part which reads; from sklearn.preprocessing import Imputer gets executed normally.

However, when I run from sk.preprocessing import Imputer, I get the following error:

from sk.preprocessing import Imputer
Traceback (most recent call last):`
File "<ipython-input-84-fc12144914d1>", line 1, in <module>`
    from sk.preprocessing import Imputer`
    ModuleNotFoundError: No module named 'sk'`

And from skl import Imputer yields the following:

from skl import Imputer`
Traceback (most recent call last):`
File "<ipython-input-85-1e925587d122>", line 1, in <module>`
        from skl import Imputer`
ModuleNotFoundError: No module named 'skl'`

Why am I not able to create a shortcut for the Library?

Community
  • 1
  • 1
  • You cannot use aliases for import. You can use them only for declaring. Something like `imputer = skl.Imputer()` or `imputer = sk.preprocessing.Imputer()` should work. – Vivek Kumar Jan 10 '18 at 09:09
  • Possible duplicate of [Import modules using an alias](https://stackoverflow.com/questions/42459939/import-modules-using-an-alias) – Vivek Kumar Jan 10 '18 at 09:15

1 Answers1

0

Because it is wrong to do so. The right way do do it is as you have written already.

from sklearn.preprocessing import Imputer 

the __init__.py in the preprocessing directory of sklearn defines the possible imports from that level.

The below is a valid aliasing and i think is what you are looking for.

from sklearn.preprocessing import Imputer as imp