''LinearRegression' object has no attribute 'summary'
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'
Solution 1:[1]
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)
Solution 2:[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()
Solution 3:[3]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pixel_teK |
| Solution 2 | Franch Dressing |
| Solution 3 | aditya nagdiya |
