我知道glmnet默认情况下没有规范拦截,但无论如何我想这样做。我正在查看this question并尝试执行whuber建议(添加常量变量并将参数intercept
转换为FALSE
),但结果是glmnet不适合添加也是不变的。
library(dplyr)
library(glmnet)
X <-
mtcars %>%
mutate(intercept = 1) %>%
select(-c(mpg)) %>%
as.matrix()
y <-
mtcars %>%
select(mpg) %>%
as.matrix()
model <- glmnet(X, y, intercept = FALSE, alpha = 0, lambda = 0)
coef(model)