我正在训练一个分别带有两个包的线性模型.
然而,我意识到,就变量系数而言,这两个结果之间存在巨大差异.
def test(x, y, model):
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.3, random_state=101)
regr = linear_model.LinearRegression()
regr.fit(x_train, y_train)
lr = sm.OLS(y_train, x_train).fit()
print(lr.params)
print(regr.coef_)
Above is the code I used. Surprisingly, the coefficient difference is so huge that it gives completely different predictions.
这两个模型都以相同的顺序列出变量,所以我现在真的很困惑.你知道哪里出了问题吗?谢谢!