Matlab 中的岭回归和 OLS 回归

Ridge regression and OLS regression in Matlab

岭回归与 OLS 回归略有不同。在数学上,OLS 回归使用公式

其中岭回归使用公式

我想使用岭回归来避免多重共线性,但得到了非常奇怪的结果,这比简单地使用 regress() 差得多。在 matlab 中,要调用函数 ridge,必须输入 X、Y 和 k 值。理论上,如果 k 设置为零,这些方程应该是相同的;但是,当在我的代码中使用相同的 X 和 Y 值调用两者时,我会收到两个非常不同的 B 矩阵(如下所示)。有人可以解释为什么会这样吗?

b_ridge = ridge(Y_current,X, 0)

    12.4525
    9.0099
    0.2808
    -1.5426
    -1.1107

b_regress = regress(Y_current,X)

    3.5586
    0.8805
    0.1670
    -0.3934
    -0.8526

根据 ridge 文档:

The results are computed after centering and scaling the x columns so they have mean 0 and standard deviation 1.

下面是一个使用列向量的例子:

>> x = randn(5,1);
>> y = randn(5,1);
>> ridge(y, x, 0)
ans =
  -0.045681220595243
>> regress(y, x)
ans =
  -0.028738686366027
>> regress(y, (x-mean(x))/std(x))
ans =
  -0.045681220595243