Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

'LinearRegression' object has no attribute 'summary'

Writer 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'

2

3 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.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy