Search code examples
pythonscikit-learnpca

ImportError: cannot import name 'LatentDirichletAllocation' when importing PCA


I keep getting the error:

ImportError: cannot import name 'LatentDirichletAllocation'

full traceback:

Traceback (most recent call last):
  File "/home/path/to/file/pca.py", line 7, in <module>
    from sklearn.decomposition import PCA
  File "/home/user/.local/lib/python3.6/site-packages/sklearn/decomposition/__init__.py", line 19, in <module>
    from ._online_lda import LatentDirichletAllocation
ImportError: cannot import name 'LatentDirichletAllocation'

when I try to import PCA using:

sklearn.decomposition import PCA

I deleted the sklearn folder and still get the error.


Solution

  • Broken installation.

    Try:

    For Python 2

    pip uninstall scikit-learn
    pip install -U scikit-learn==0.20.4
    

    For Python 3

    pip3 uninstall scikit-learn
    pip3 install -U scikit-learn==0.21.3