欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

AttributeError: module 'sklearn' has no attribute 'linear_model'

程序员文章站 2022-07-14 15:14:43
...

AttributeError: module 'sklearn' has no attribute 'linear_model'

  • 在调用sklearn库的时候出现Traceback错误。
import sklearn
model = sklearn.linear_model.LinearRegression()
  • 错误如图所示:
    AttributeError: module 'sklearn' has no attribute 'linear_model'
Traceback (most recent call last):
  File "/Users/zhangzhenkai/Documents/TensorflowLearn/ch1/sec1/Scikit_Learn.py", line 37, in <module>
    model = sklearn.linear_model.LinearRegression()
AttributeError: module 'sklearn' has no attribute 'linear_model'
  • 后来在Google上搜了一下,找到了解决方法,只需将代码修改为:
from sklearn.linear_model import LinearRegression
model = sklearn.linear_model.LinearRegression()
  • 同样地,AttributeError: module ‘sklearn’ has no attribute ‘datasets’,也可以这样解决。
AttributeError: module 'sklearn' has no attribute 'datasets'