0
import statsmodels.api as sm 


x1 = np.array([3,4,6,8,9])
x2 = np.array([1,1,3,6,4])
x3 = np.array([2,2,5,6,9])
y =  np.array([2,3,6,5,8])

xn1 = x1.reshape(-1,1)
xn2 = x2.reshape(-1,1)
xn3 = x3.reshape(-1,1)

X = np.concatenate((xn1,xn2,xn3),axis=1)

yn1 = y.reshape(-1,1)

reg = linear_model.LinearRegression()
reg.fit(X,y)
print(reg.coef_)
print(reg.intercept_)

model = sm.OLS(y,X).fit() 
print(model.summary())

output from linear regression is [ 0.66424419 -0.48982558 0.48401163]

whereas as output from the statsmodel is as below

x1, coeff = 0.6455, std err = 0.425
x2, coeff =-0.4823, std err =0.388
x3, coeff = 0.4948, std err =0.412

so the figures are not matching, what is the reason, experts please advise.

StupidWolf
  • 45,075
  • 17
  • 40
  • 72
  • Output from from sklearn import linear_model and output from import statsmodels.api as sm is not matching regards to the linear coeficients. What is difference – rahan nix Feb 05 '21 at 14:15
  • 2
    you don't have an intercept in the statsmodels version, one parameter less – Josef Feb 05 '21 at 15:01

0 Answers0