python - sklearn 'preprocessor' 导入时子模块不可用

标签 python python-3.x scikit-learn pip sklearn-pandas

我发现了一些其他帖子,例如 this one提示无法导入有关 sklearn 的一些内容,但我已经尝试了所有建议的解决方案(归结为:在每种情况下 pip3 install -Uapt install ,也在询问预处理器以外的问题的帖子中),但它仍然没有帮助。

我遇到的问题是:

>>> import sklearn
>>> sklearn.__version__
'0.20.3'
>>> sklearn.preprocessor
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'sklearn' has no attribute 'preprocessor'
>>> from sklearn import preprocessor
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'preprocessor'

安装假定正确的软件包时的输出如下:

$ pip3 install -U scikit-learn
Collecting scikit-learn
  Using cached https://files.pythonhosted.org/packages/5e/82/c0de5839d613b82bddd088599ac0bbfbbbcbd8ca470680658352d2c435bd/scikit_learn-0.20.3-cp36-cp36m-manylinux1_x86_64.whl
Collecting numpy>=1.8.2 (from scikit-learn)
  Using cached https://files.pythonhosted.org/packages/35/d5/4f8410ac303e690144f0a0603c4b8fd3b986feb2749c435f7cdbb288f17e/numpy-1.16.2-cp36-cp36m-manylinux1_x86_64.whl
Collecting scipy>=0.13.3 (from scikit-learn)
  Using cached https://files.pythonhosted.org/packages/7f/5f/c48860704092933bf1c4c1574a8de1ffd16bf4fde8bab190d747598844b2/scipy-1.2.1-cp36-cp36m-manylinux1_x86_64.whl
Installing collected packages: numpy, scipy, scikit-learn
Successfully installed numpy-1.16.2 scikit-learn-0.20.3 scipy-1.2.1

或者:

$ sudo apt autoremove
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 49 not upgraded.

正如您所看到的,该软件包应该通过两种不同的方式正确安装,但它仍然不起作用。我还尝试卸载其中一个(以防它们相互干扰),但这也没有解决任何问题。

有谁知道为什么这对我不起作用?如果我需要提供有关我的安装的任何其他信息,我很乐意提供。

最佳答案

我以前也遇到过这种情况,这是解决方案

import sklearn.preprocessing # or from sklearn import preprocessing

关于python - sklearn 'preprocessor' 导入时子模块不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55670856/

相关文章:

python - 计算 3D 球面掩膜的直径线

python - 如何在mongodb shell中设置mongoengine的ReferenceField值?

python - 玛雅 python : How do I get the scene name but not the path or extension

python - Django:无法在指定中间模型的 ManyToManyField 上设置值

python - 如何将多个分区的 .gzip 文件读入 Spark Dataframe?

python - 如何同时监控loss和val_loss以避免神经网络对训练集或测试集过度拟合?

python - Scikit 学习交叉验证拆分

python - 在 self._compute_kernel(X) 中引发 ValueError ("X.shape[0] should be equal to X.shape[1]")

python - 在 macOS 上将 Python 版本升级到 3.9 现在会为某些文件读取代码提供 “variable not defined” 错误

python - Instagram 关闭 API 服务后,如何使用 python 将照片上传到 Instagram