问题描述
我在 SciKit-Learn 包中遇到了一些奇怪的问题.SciKit-Learn 包中有一个分解"模块,它应该包含 LatentDirichletAllocation([…]) 函数.请参阅此处的文档:"https://scikit-learn.org/stable/modules/classes.html#module-sklearn.decomposition"
I got some strange problem at SciKit-Learn package. There is "decomposition" module inside SciKit-Learn package, which should contain LatentDirichletAllocation([…]) function. See documentation here:"https://scikit-learn.org/stable/modules/classes.html#module-sklearn.decomposition"
当我尝试导入分解"模块时:from sklearn import as 分解
它给出了错误:
When I tried to import "decomposition" module: from sklearn import as decomposition
it gives error:
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 类.
Most of the functions are here but there are no traces of the "LatentDirichletAllocation" function. Yet I did see LatentDirichletAllocation class defined in the _online_lda.py file.
命令 python3 -c "import sklearn; sklearn.show_versions()"
打印所有需要的版本:
Command python3 -c "import sklearn; sklearn.show_versions()"
prints all versions required:
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 运行良好,直到我尝试导入分解"模块).
So I assume all requirements were met here. (BTW SciKit-Learn worked fine till I tried to import "decomposition" module).
我按照此处的描述安装了 SciKit-Learn 软件包:"https://scikit-learn.org/stable/install.html"使用命令 pip3 install -U scikit-learn
我确实重新安装了几次,但得到了相同的结果.
I installed the SciKit-Learn package as it was described here: "https://scikit-learn.org/stable/install.html"using command pip3 install -U scikit-learn
I did reinstall that several times but got same result.
我做错了什么?我是否需要将缺少的LatentDirichletAllocation"函数添加到分解"模块中?如果是这样 - 如何?我应该以不同的方式安装整个包吗?
What do I do wrong? Do I need to add missing "LatentDirichletAllocation" function into the "decomposition" module? If so - how? Should I install the whole package somehow different way?
谢谢.
推荐答案
我今天遇到了同样的问题.我回到scikit-learn 0.21之前的版本解决了:
I had the same problem today. I solved it by going back to the previous version 0.21 of scikit-learn:
pip3 install scikit-learn==0.21
我认为来自 glemaitre 的答案(https://stackoverflow.com/a/59328446/10429267)显示了更好的解决方案.
I think the answer from glemaitre (https://stackoverflow.com/a/59328446/10429267) shows a better solution.
这篇关于SciKit-Learn 的分解模块中未安装 LatentDirichletAllocation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!