'LinearRegression' object has no attribute 'summary'
Andrew Henderson
from sklearn.linear_model import LinearRegression
lr= LinearRegression()
X=[[1.1,1.3,1.5]]
y=[[39343,46205,37731]]
lr.fit(X, y)
lr.summary()AttributeError Traceback (most recent call last) in ----> 1 lr.summary()
AttributeError: 'LinearRegression' object has no attribute 'summary'
23 Answers
The method summary(), simply does not exist under the name lr, if you are trying to access the coefficients you can use :
reg.coef_other than that, you would be better off checking the docs : sklearn.linear_model.LinearRegression docs
or you can instantly check what names you can access under lr using :
dir(lr)or read the help docs using :
help(lr) 2 I have this problem all the time. It's because you need to use statsmodel's Ordinary Least Square function (sm.OLS(y,x,data=data_frame)) before fitting the model. You should probably add a constant to the x axis as well:
from sklearn.linear_model import LinearRegression
import statsmodels.api as sm
lr= LinearRegression()
X=[[1.1,1.3,1.5]]
y=[[39343,46205,37731]]
X = sm.add_constant(X)
model = sm.OLS(y,X)
fitted_model = model.fit()
fitted_model.summary() 1 I was confused b/w R's regression and python's.
and yes if u want to see the similar summary report in python then , statsmodels' Ordinary Least Square is the way to do it.