首页 > 解决方案 > importing subpackages of sci-kit learn 'Unknown location'

问题描述

I try to do some PCA and TSNE analyses. I want to use sklearn to import the PCA and TSNE package. Internet says that I should use these imports

from sklearn.decomposition import PCA
from sklearn.manifold import TSNE

https://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html https://scikit-learn.org/stable/modules/generated/sklearn.manifold.TSNE.html

However, I get this message when I try to import those.

ImportError: cannot import name 'PCA' from 'sklearn.decomposition' (unknown location)

I did install sklearn and am able to import sklearn.decomposition and sklearn.manifold. However, If I I try to do this:

import sklearn.decomposition as decom
decom.PCA

I get the same ImportError. I tried reinstalling sklearn and updating it, but that doesn't solve the problem. Does one of you have a clue of what I'm doing wrong? I'm using Python 3.7.8 and use jupyter lab with MiniConda.

The documentation of sklearn is version 23.2 and that is the same version as my scikit-learn is.

EDIT: I created a totally new virtual environment and now my dir(decom) is totally different. And those packages for PCA and TSNE are working. Could somebody enlighten me why those are not working in the my current environment? Does it have to do with incompatible packages? I did not get any warning for it. It is sort of solved, yet I'm curious what the reason is and how I can fix it in the future.

标签: pythonimportscikit-learnpackage

解决方案


推荐阅读