我尝试使用扩展的波士顿数据集训练线性回归模型:
from mglearn.datasets import load_extended_boston
X, y = load_extended_boston()
from sklearn.linear_model import LinearRegression
linearReg = LinearRegression()
linearReg.fit(X, y)
对于X
中的每个特征,LinearRegression
给出了相应的系数
但是,X^TX不是可逆的。因此,当我在R
中拟合这个线性模型时,程序将自动删除一个特性以找到解决方案
sklearn.linear\u model.LinearRegression是否使用了一些不同的算法
您可以尝试
Ridge regression
,这是LinearRegression
加上L2正则化。L2正则化意味着它不仅最小化到目标的平方距离,而且还试图保持系数较小。这使得它对于共线数据集更加稳定从文档中:
见https://scikit-learn.org/stable/modules/linear_model.html#ridge-regression 和 https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.Ridge.html
我不同意你的看法
也许它不是那样的意思,但从技术上讲,你必须有一个可逆的协方差矩阵来做中的实现是必要的。但我认为做一些正规化是明智的。这样想:如果你的问题是你的问题有很多解决方案(这就是共线的意思),你想怎么解决?你想选择任何一种解决方案,还是想提出一个标准,说明哪种解决方案是最好的,例如,最常见的
linear regression/least squares
。例如,您可以使用QR分解来完成。我猜他的意思是,这对于^{相关问题 更多 >
编程相关推荐