R glmnet标准化的不同结果=错误
我正在运行R glmnet标准化的不同结果=错误,r,glmnet,R,Glmnet,我正在运行glmnet,并尝试在使用standarized=FALSE预标准化变量时查看差异 library(glmnet) data(QuickStartExample) ### Standardized Way x_standardized <- scale(x, center = TRUE, scale = TRUE) y_standardized <- scale(y, center = TRUE, scale = TRUE) cv_standardized <- cv
glmnet
,并尝试在使用standarized=FALSE
预标准化变量时查看差异
library(glmnet)
data(QuickStartExample)
### Standardized Way
x_standardized <- scale(x, center = TRUE, scale = TRUE)
y_standardized <- scale(y, center = TRUE, scale = TRUE)
cv_standardized <- cv.glmnet(x_standardized, y_standardized,
intercept = FALSE,
standardize = FALSE, standardize.response = FALSE)
destandardized_coef <- coef(cv_standardized)[-1] * sd(y) / apply(x, 2, sd)
destandardized_coef
mean(y) - sum(destandardized_coef * colMeans(x))
### Let glmnet Stanardize
cv_normal <- cv.glmnet(x, y)
coef(cv_normal, cv_normal$lambda.min) %>% as.numeric()
我的问题是,如何提取相同的结果,以及为什么目前的系数以这种方式不同
提前谢谢
personal_standardize glmnet_standardize
(Intercept) 0.1536661 0.14867414
V1 1.3019575 1.33377821
V2 . .
V3 0.6422426 0.69787701
V4 . .
V5 -0.7892388 -0.83726751
V6 0.4944794 0.54334327
V7 . 0.02668633
V8 0.2943189 0.33741131
V9 . .
V10 . .
V11 0.1058440 0.17105029
V12 . .
V13 . .
V14 -1.0402312 -1.07552680
V15 . .
V16 . .
V17 . .
V18 . .
V19 . .
V20 -0.9791172 -1.05278699