gpt4 book ai didi

python-3.x - SciKit-Learn 的分解模块中未安装 LatentDirichletAllocation

转载 作者:行者123 更新时间:2023-12-01 11:11:56 25 4
gpt4 key购买 nike

我在 SciKit-Learn 包中遇到了一些奇怪的问题。SciKit-Learn 包中有“分解”模块,其中应该包含 LatentDirichletAllocation([…]) 函数。请参阅此处的文档:"https://scikit-learn.org/stable/modules/classes.html#module-sklearn.decomposition "

当我尝试导入“分解”模块时:从 sklearn 导入为分解它给出了错误:

Traceback (most recent call last):
File "tf_1_day_scikit_dnn.py", line 12, in <module>
from sklearn import decomposition
File "/home/developer1/.local/lib/python3.6/site-packages/sklearn/decomposition/__init__.py", line 19, in <module>
from ._online_lda import LatentDirichletAllocation
ImportError: cannot import name 'LatentDirichletAllocation'

命令:ls -al ~/.local/lib/python3.6/site-packages/sklearn/decomposition 显示:

drwxr-xr-x  4 developer1 developer1   4096 Dec  9 00:45 .
drwxr-xr-x 33 developer1 developer1 4096 Dec 9 00:45 ..
-rw-r--r-- 1 developer1 developer1 5490 Dec 9 00:44 _base.py
-rw-r--r-- 1 developer1 developer1 480 Dec 9 00:44 base.py
-rwxr-xr-x 1 developer1 developer1 179440 Dec 9 00:44 _cdnmf_fast.cpython-36m-x86_64-linux-gnu.so
-rwxr-xr-x 1 developer1 developer1 175344 Dec 3 00:09 cdnmf_fast.cpython-36m-x86_64-linux-gnu.so
-rw-r--r-- 1 developer1 developer1 498 Dec 9 00:44 cdnmf_fast.py
-rw-r--r-- 1 developer1 developer1 54528 Dec 9 00:44 _dict_learning.py
-rw-r--r-- 1 developer1 developer1 507 Dec 9 00:44 dict_learning.py
-rw-r--r-- 1 developer1 developer1 12572 Dec 9 00:44 _factor_analysis.py
-rw-r--r-- 1 developer1 developer1 513 Dec 9 00:44 factor_analysis.py
-rw-r--r-- 1 developer1 developer1 20866 Dec 9 00:44 _fastica.py
-rw-r--r-- 1 developer1 developer1 490 Dec 9 00:44 fastica_.py
-rw-r--r-- 1 developer1 developer1 14076 Dec 9 00:44 _incremental_pca.py
-rw-r--r-- 1 developer1 developer1 513 Dec 9 00:44 incremental_pca.py
-rw-r--r-- 1 developer1 developer1 1401 Dec 9 00:44 __init__.py
-rw-r--r-- 1 developer1 developer1 13597 Dec 9 00:44 _kernel_pca.py
-rw-r--r-- 1 developer1 developer1 498 Dec 9 00:44 kernel_pca.py
-rw-r--r-- 1 developer1 developer1 47255 Dec 9 00:44 _nmf.py
-rw-r--r-- 1 developer1 developer1 477 Dec 9 00:44 nmf.py
-rwxr-xr-x 1 developer1 developer1 62056 Dec 3 00:09 _online_lda.cpython-36m-x86_64-linux-gnu.so
-rwxr-xr-x 1 developer1 developer1 62064 Dec 9 00:44 _online_lda_fast.cpython-36m-x86_64-linux-gnu.so
-rw-r--r-- 1 developer1 developer1 513 Dec 9 00:44 online_lda_fast.py
-rw-r--r-- 1 developer1 developer1 30471 Dec 9 00:44 _online_lda.py
-rw-r--r-- 1 developer1 developer1 498 Dec 9 00:44 online_lda.py
-rw-r--r-- 1 developer1 developer1 22807 Dec 9 00:44 _pca.py
-rw-r--r-- 1 developer1 developer1 477 Dec 9 00:44 pca.py
drwxr-xr-x 2 developer1 developer1 4096 Dec 9 00:45 __pycache__
-rw-r--r-- 1 developer1 developer1 855 Dec 9 00:44 setup.py
-rw-r--r-- 1 developer1 developer1 13654 Dec 9 00:44 _sparse_pca.py
-rw-r--r-- 1 developer1 developer1 498 Dec 9 00:44 sparse_pca.py
drwxr-xr-x 3 developer1 developer1 4096 Dec 9 00:45 tests
-rw-r--r-- 1 developer1 developer1 8346 Dec 9 00:44 _truncated_svd.py
-rw-r--r-- 1 developer1 developer1 507 Dec 9 00:44 truncated_svd.py

大部分函数都在这里,但没有“LatentDirichletAllocation”函数的踪迹。然而,我确实在 _online_lda.py 文件中看到了 LatentDirichletAllocation 类的定义。

命令 python3 -c "import sklearn; sklearn.show_versions()" 打印所有需要的版本:

System:
python: 3.6.8 (default, Oct 7 2019, 12:59:55) [GCC 8.3.0]
executable: /usr/bin/python3
machine: Linux-4.15.0-65-generic-x86_64-with-Ubuntu-18.04-bionic

Python dependencies:
pip: 9.0.1
setuptools: 42.0.2
sklearn: 0.22
numpy: 1.17.4
scipy: 1.3.3
Cython: None
pandas: 0.25.3
matplotlib: 3.1.2
joblib: 0.14.0

Built with OpenMP: True

所以我假设这里满足了所有要求。 (顺便说一句,在我尝试导入“分解”模块之前,SciKit-Learn 工作正常)。

我按照此处的描述安装了 SciKit-Learn 包:“https://scikit-learn.org/stable/install.html”使用命令 pip3 install -U scikit-learn我确实重新安装了几次,但得到了相同的结果。

我做错了什么?我是否需要将缺少的“LatentDirichletAllocation”函数添加到“分解”模块中?如果是这样 - 怎么样?我应该以不同的方式安装整个软件包吗?

谢谢。

最佳答案

我今天遇到了同样的问题。我通过回到以前的 scikit-learn 0.21 版本解决了这个问题:

pip3 install scikit-learn==0.21

编辑:我认为来自 glemaitre ( https://stackoverflow.com/a/59328446/10429267 ) 的答案显示了更好的解决方案。

关于python-3.x - SciKit-Learn 的分解模块中未安装 LatentDirichletAllocation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59240556/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com