$ \ lambda = 0 $的LASSO和OLS在R glmnet中产生不同的结果 [英] LASSO with $\lambda = 0$ and OLS produce different results in R glmnet
本文介绍了$ \ lambda = 0 $的LASSO和OLS在R glmnet中产生不同的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望没有惩罚($ \ lambda = 0 $)的LASSO会产生与OLS拟合相同(或非常相似)的系数估计.但是,我在R中得到了不同的系数估计,将相同的数据(x,y)放入
I expect LASSO with no penalization ($\lambda=0$) to yield the same (or very similar) coefficient estimates as an OLS fit. However, I get different coefficient estimates in R putting the same data (x,y) into
-
glmnet(x, y , alpha=1, lambda=0)
适用于LASSO,没有惩罚,并且 -
lm(y ~ x)
用于OLS拟合.
glmnet(x, y , alpha=1, lambda=0)
for LASSO fit with no penalization andlm(y ~ x)
for OLS fit.
那是为什么?
推荐答案
您使用的函数错误. x
应该是模型矩阵.不是原始的预测值.当您这样做时,您将获得完全相同的结果:
You're using the function wrong. The x
should be the model matrix. Not the raw predictor value. When you do that, you get the exact same results:
x <- rnorm(500)
y <- rnorm(500)
mod1 <- lm(y ~ x)
xmm <- model.matrix(mod1)
mod2 <- glmnet(xmm, y, alpha=1, lambda=0)
coef(mod1)
coef(mod2)
这篇关于$ \ lambda = 0 $的LASSO和OLS在R glmnet中产生不同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文