3

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.

startswithH
  • 309
  • 4
  • 14

2 Answers2

4

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
seralouk
  • 30,938
  • 9
  • 118
  • 133
3

Had this problem, fully uninstalling and re-installing scikit-learn via pip fixed it.

parsethis
  • 7,998
  • 3
  • 29
  • 31