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())
线性回归的输出是[ 0.66424419 -0.48982558 0.48401163]
而statsmodel的输出如下
x1, coeff = 0.6455, std err = 0.425
x2, coeff =-0.4823, std err =0.388
x3, coeff = 0.4948, std err =0.412
所以数字不匹配,是什么原因,请高手指教。