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

时间:2021-09-28 19:56:26

  以下导入方式报错

  

import sklearn
lr = sklearn.linear_model.LinearRegression() # 需要导入sklearn的linear_model

  修改导入方式即可如下:

from sklearn.linear_model import LinearRegression
lr = LinearRegression() # 需要导入sklearn的linear_model