主要内容

ridge

山脊回归

描述

example

B= ridge(y,X,k)返回系数估计脊回归模型预测数据数据Xand the responsey。每一列B对应于特定脊参数k。默认情况下,功能计算B将预测变量的中心和缩放缩放为具有平均0和标准偏差1.由于模型不包含恒定项,请勿将1列添加到X

example

B= ridge(y,X,k,scaled)specifies the scaling for the coefficient estimates inB。什么时候scaledis1(默认),ridge不会将系数还原到原始数据量表。什么时候scaledis0,ridgerestores the coefficients to the scale of the original data. For more information, see系数缩放

例子

collapse all

Perform ridge regression for a range of ridge parameters and observe how the coefficient estimates change.

加载乙炔data set.

load乙炔

乙炔包含对预测变量的观察x1,x2, andX3, and the response variabley

绘制预测变量相互对抗。观察变量之间的任何相关性。

plotmatrix([x1 x2 x3])

MATLAB图

For example, note the linear correlation betweenx1andX3

对具有相互作用项的多线性模型的计算系数估计,用于一系列脊参数。利用x2fx创建互动术语和ridgeto perform ridge regression.

x = [x1 x2 x3];d = x2fx(x,'interaction'); D(:,1) = [];% No constant termk = 0:1e-5:5e-3;b =脊(y,d,k);

绘制山脊痕迹。

figure plot(k,B,'行宽',2)Ylim([ -  100 100])网格onXlabel(“山脊参数”) ylabel(“标准化系数”) 标题('Ridge Trace') 传奇('x1','x2','x3','x1x2','x1x3','x2x3')

图包含一个轴。带有标题脊跟踪的轴包含6个类型线的对象。这些对象代表x1,x2,x3,x1x2,x1x3,x2x3。

估计值稳定在图的右侧。请注意,系数x2x3互动项在脊参数的值时更改符号 5 * 1 0 - 4

使用脊回归预测每加仑英里(MPG)值。

加载卡比格data set.

load卡比格x = [加速度重量位移马力];y = mpg;

将数据分为培训和测试集。

n = length(y); rng('默认')%可再现性c = cvpartition(n,'坚持',0.3); idxTrain = training(c,1); idxTest = ~idxTrain;

找到脊回归模型的系数(k = 5)。

k = 5; b = ridge(y(idxTrain),X(idxTrain,:),k,0);

PredictMPGvalues for the test data using the model.

yhat = b(1) + x(idxtest,:)*b(2:end);

使用参考线比较预测值与每加仑实际英里(MPG)值。

scatter(y(idxTest),yhat) holdonplot(y(idxTest),y(idxTest)) xlabel(“实际MPG”) ylabel('Predicted MPG') holdoff

图包含一个轴。这axes contains 2 objects of type scatter, line.

Input Arguments

collapse all

响应数据,指定为n-经过-1 numeric vector, wheren是观察的数量。

数据类型:单身的|双倍的

预测数据, specified as ann-经过-pnumeric matrix. The rows ofX对应于n观察和列X对应于p预测指标。

数据类型:单身的|双倍的

Ridge parameters, specified as a numeric vector.

例子:[0.2 0.3 0.4 0.5]

数据类型:单身的|双倍的

缩放标志that determines whether the coefficient estimates inB恢复到原始数据的比例,指定为0or1。如果scaledis0, thenridgeperforms this additional transformation. In this case,Bcontainsp+1coefficients for each value ofk,第一行B对应于模型中的恒定项。如果scaledis1,然后该软件省略了其他转换,并且Bcontainspcoefficients without a constant term coefficient.

输出参数

collapse all

Coefficient estimates, returned as a numeric matrix. The rows ofB对应于predictors inX,以及B对应于ridge parametersk

如果scaledis1, thenB是一个p-经过-m矩阵,哪里m是元素中的数量k。如果scaledis0, thenB是一个(p+1)-by-m矩阵。

More About

collapse all

山脊回归

山脊回归是一个method for estimating coefficients of linear models that include linearly correlated predictors.

Coefficient estimates for multiple linear regression models rely on the independence of the model terms. When terms are correlated and the columns of the design matrixX具有近似线性依赖性,矩阵(XTX)–1接近单数。因此,最小二乘的估计值

β ^ = ( X T X ) - 1 X T y

is highly sensitive to random errors in the observed responsey,产生较大的差异。例如,当您在没有实验设计的情况下收集数据时,可能会出现多重共线性的这种情况。

脊回归通过使用回归系数估算回归系数来解决多重共线性的问题

β ^ = ( X T X + k I ) - 1 X T y

在哪里k是山脊参数,Iis the identity matrix. Small, positive values ofkimprove the conditioning of the problem and reduce the variance of the estimates. While biased, the reduced variance of ridge estimates often results in a smaller mean squared error when compared to least-squares estimates.

系数缩放

脊回归模型的系数估计值的缩放取决于scaledinput argument.

假设山脊参数k等于0。ridge, 什么时候scaledis equal to1, are estimates of thebi1in the multilinear model

yμy=b11z1+ ... +bp1zp+ε

在哪里zi= (xiμi)/σiare the centered and scaled predictors,yμyis the centered response, andε是一个n error term. You can rewrite the model as

y=b00+b10x1+ ... +bp0xp+ε

with b 0 0 = μ y - i = 1 p b i 1 μ i σ i and b i 0 = b i 1 σ i 。这bi0术语对应于返回的系数ridge什么时候scaledis equal to0

More generally, for any value ofk, ifB1 =山脊(Y,X,K,1), then

m = mean(X); s = std(X,0,1)'; B1_scaled = B1./s; B0 = [mean(y)-m*B1_scaled; B1_scaled]

在哪里B0 =山脊(Y,X,K,0)

提示

  • ridge零食NaNXory作为缺失值。ridge从脊回归拟合中遗漏了缺少值的观察值。

  • 通常,设置scaledequal to1to produce plots where the coefficients are displayed on the same scale. See山脊回归for an example using a ridge trace plot, where the regression coefficients are displayed as a function of the ridge parameter. When making predictions, setscaledequal to0。For an example, see使用脊回归预测值

Alternative Functionality

  • 脊,拉索和弹性净正则化是估计线性模型系数的所有方法,同时惩罚大系数。惩罚的类型取决于该方法(请参阅More About更多细节)。要执行套索或弹性净正则化,请使用套索instead.

  • 如果您具有高维的完整或稀疏预测数据,则可以使用fitrlinearinstead ofridge。什么时候usingfitrlinear,指定“正则化”,“山脊”名称值对参数。设置值'Lambda'名称值对参数与您选择的Ridge参数的向量。fitrlinearreturns a trained linear modelMdl。You can access the coefficient estimates stored in thebeta使用模型的属性Mdl.Beta

参考

[1] Hoerl,A。E.和R. W. Kennard。“脊回归:对非正交问题的偏见估计。”技术测量学。卷。12,第1号,1970年,第55-67页。

[2] Hoerl, A. E., and R. W. Kennard. “Ridge Regression: Applications to Nonorthogonal Problems.”技术测量学。卷。12,第1号,1970年,第69-82页。

[3] Marquardt, D. W. “Generalized Inverses, Ridge Regression, Biased Linear Estimation, and Nonlinear Estimation.”技术测量学。卷。12,第3期,1970年,第591–612页。

[4] Marquardt, D. W., and R. D. Snee. “Ridge Regression in Practice.”这American Statistician。卷。29, No. 1, 1975, pp. 3–20.

Introduced before R2006a