我有一个关于 glmnet 包中的标准化选项的问题。
我知道为了使系数有意义,回归分析需要缩放或标准化数据集。
通常,对于线性回归(例如,使用 R 中的 glm 函数),我在运行 glm 模型之前使用 scale() 函数手动缩放数据集。
然而,似乎在使用 glmnet 包(用于正则化回归)时,标准化选项确实标准化了数据集,从而使系数本身有意义(可比较)。我对么?
如果这是正确的,假设我运行以下代码。事实证明,变量“x3”的系数最高(在绝对值范围内)。那么我可以得出结论,变量“x3”是区分类别中最重要的变量吗???
我期待听到任何意见!谢谢。
set.seed(12345)
example.dat <- data.frame(Category = rbinom(100, 1, 0.5),
x1 = rpois(100, 10),
x2 = rnorm(100, 3, 10),
x3 = rbeta(100, 8, 20),
x4 = rnorm(100, -3, 45),
x5 = rnorm(100, 1000, 10000))
sample = sample.split(example.dat$Category, SplitRatio = .70)
train = subset(example.dat, sample == TRUE)
test = subset(example.dat, sample == FALSE)
set.seed(12345)
lasso.fit <- cv.glmnet(data.matrix(train[,-1]),
train[,1],
family = "binomial",
nfolds = nrow(train), # LOOCV
grouped = FALSE,
type.measure = "class",
alpha = 0.6,
standardize = TRUE,
standardize.response = TRUE)
print(lasso.fit)
coef <- as.matrix(abs(coef(lasso.fit, s = "lambda.1se")))
coef.order <- as.matrix(coef[order(coef, decreasing = TRUE),])
rownames(as.matrix(coef.order[coef.order[,1]>0,]))
# [1] "x3" "(Intercept)"