【问题标题】:ImportError: cannot import name 'LatentDirichletAllocation' from 'sklearn.decomposition._online_lda'ImportError:无法从“sklearn.decomposition._online_lda”导入名称“LatentDirichletAllocation”
【发布时间】:2025-12-26 13:20:20
【问题描述】:

每当我从 sklearn 导入任何 Tree 模块时都会遇到错误。下面的示例代码

from sklearn.ensemble import ExtraTreesRegressor
model = ExtraTreesRegressor()
model.fit(X,y)

我第一次运行代码时收到此错误 -

ImportError: cannot import name 'LatentDirichletAllocation' from 'sklearn.decomposition._online_lda' (C:\Users\lenovo\Anaconda3\lib\site-packages\sklearn\decomposition_online_lda.cp37-win_amd64.pyd)

之后,每当我运行相同的代码时,我都会收到以下错误 -

AttributeError: type object 'sklearn.tree.criterion.array' has no attribute 'reducecython'

同样的代码之前运行良好,但突然对我停止运行

我也尝试过卸载并重新安装 scikit-learn。任何帮助,将不胜感激。谢谢:)

【问题讨论】:

  • 尝试从conda-forge频道安装包:conda install scikit-learn -c conda-forge

标签: python scikit-learn importerror


【解决方案1】:

我认为这可能是 conda install sklearn 0.22 版的问题,正如issues 中所质疑的那样。

试试pip install -U scikit-learn

【讨论】:

  • 你不应该这样做,因为 Utkarsh Kant 使用的是conda。后面会一团糟。
【解决方案2】:

更新 scikit-learn,最准确的版本是 0.22.1

【讨论】: