1

When I tried to load from sklearn.impute import KNNImputer on Jupyter Notebook, it gave me the following error.

ImportError: cannot import name 'KNNImputer' from 'sklearn.impute' (C:\Users\aura-\Anaconda3\lib\site-packages\sklearn\impute_init_.py)

I have updated sklearn to the newest version.

(base) C:\Users\aura->pip install -U scikit-learn
Requirement already up-to-date: scikit-learn in c:\users\aura-\anaconda3\lib\site-packages (0.23.2)

But when I checked on Jupyter Notebook again import sklearn;print(sklearn.__version__), it is still showing 0.21.3

Why the update is not reflected on Jupyter Notebook?

DianZzzz
  • 37
  • 4

1 Answers1

2

Your package paths seem to be confused. The error you provide searches for the package in:

\Anaconda3\lib\site-packages

But the sci-kit learn you updated is in:

\anaconda3\lib\site-packages

When you install Anaconda, it creates the anaconda3 folder. Did you create an Anaconda3 folder?

Anyway, wherever you're running your Jupyter Notebook, Python is searching the undesired folder for the packages. Check this answer on Stack Exchange for how to edit your PYTHONPATH. I would recommend removing the path to Anaconda3, and adding the path to anaconda3 in your PYTHONPATH.

Something else you can try, if you rather:

Alternatively, use conda to create a virtual environment using conda create and conda activate to enter the environment. When in a virtual environment, if you run Jupyter then conda should direct Python to the correct path [i.e \path\to\anaconda3]. This is the primary function of conda.

Alan
  • 1,746
  • 7
  • 21