Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SKLearn - Cannot import LinearModel?

I'm trying to import LinearModel from SKLearn:

from sklearn.base import RegressorMixin, LinearModel

I can see with my own eyes, that the class is in base.py here, but the import doesn't work. Why? How can I fix this?

ImportError: cannot import name 'LinearModel'
like image 974
lte__ Avatar asked Sep 10 '26 08:09

lte__


2 Answers

What exactly are you trying to do? As far as I can see it, LinearModel is only a base class.

Is this maybe what you are looking for? http://scikit-learn.org/stable/modules/linear_model.html#ordinary-least-squares

Edit:

Oh and by the way, if you really need the base class, I believe it is located in sklearn.linear_model.base. Import it using:

from sklearn.linear_model.base import LinearModel
like image 76
tomsal Avatar answered Sep 12 '26 21:09

tomsal


As of sklearn v24 the previous solution from sklearn.linear_model.base import LinearModel doesn't work anymore.

New workaround is to import whatever class you need/want to inherit directly. For me, that was from sklearn.linear_model import LinearRegression

like image 23
Dave Liu Avatar answered Sep 12 '26 23:09

Dave Liu