python 岭回归解释结果

python Ridge regression interpreting results

我将 python 与 sklearn 和 statsmodels 一起使用来创建回归模型。 这是我第一次使用 Ridge 回归。但是,我不明白结果是什么意思。例如。

当我打印时

print reg.intercept_
print reg.coef_

我得到的输出是

print  reg.intercept_

[[  0.00000000e+00]
 [ -5.27579034e-03]
 [  3.35202990e-03]
 [ -1.54862324e-02]
 [ -3.74392708e-02]

print reg.coef_   

[ 1.00000000e+00   4.11548523e-02   6.98464464e-01   3.88878487e-01
       5.20562949e+01 ]

无论何时,我做一个正常的线性回归我只会得到 1 个截距,但是在脊模型中我得到 5 个截距。谁能详细说明为什么以及它是什么意思?

我相信您有多个目标,如果您查看 Linear Regression under the attributes intercept_ it specifies it's independent of the model. If you look at the same documentation for Ridge Regression, 的文档,它会在属性部分指定 intercept_ : float | array, shape = (n_targets,).

您可以通过在我修改的以下代码中更改由变量 n_targets 控制的目标数量来验证这一点:

from sklearn.linear_model import Ridge
import numpy as np

n_targets=2
n_samples, n_features = 10, 5

np.random.seed(0)
y = np.random.randn(n_samples,n_targets)
X = np.random.randn(n_samples, n_features)
clf = Ridge(alpha=1.0)
clf.fit(X, y) 

print( clf.intercept_)

如果你设置 n_targets=1 你会得到 0.89586534,如果你设置 n_targets=2 你会得到 [0.7101951 0.36420037]。 我在课程 Data Analysis with Python./

中介绍了岭回归