【发布时间】:2018-03-07 10:51:42
【问题描述】:
我已经安装了 sklearn 并且能够使用命令导入 sklearn 导入sklearn
但是我发现sklearn的子模块不能被sklearn.module_name调用,例如:
In [1]: import sklearn
In [2]: sklearn.linear_model
Traceback (most recent call last):
File "<ipython-input-2-e64c575ed22e>", line 1, in <module>
sklearn.linear_model
AttributeError: 'module' object has no attribute 'linear_model'
同时,我可以直接导入 sklearn.linear_model
In [3]: import sklearn.linear_model
In [4]: sklearn.linear_model
Out[4]: <module 'sklearn.linear_model' from
'C:\Users\sng\AppData\Local\conda\conda\envs\python2\lib\site-
packages\sklearn\linear_model\__init__.pyc'>
上述不正确,例如在matplotlib中:
In [5]: import matplotlib
In [6]: matplotlib.pyplot
Out[6]: <module 'matplotlib.pyplot' from
'C:\Users\sng\AppData\Local\conda\conda\envs\python2\lib\site-
packages\matplotlib\pyplot.pyc'>
我很好奇这里发生了什么?包 sklearn 与其他包不同吗?我的 IDE 是用于 python 2.7 的 Spyder
【问题讨论】:
-
尝试
from sklearn import *然后sklearn.linear_model.LinearRegression()
标签: python scikit-learn spyder