我能够使用glmnet使用套索方法创建线性模型。现在,我想使用该模型来获取预测值。
LASSO_BestK_LM <- cv.glmnet(
x = X,
y = as.matrix(dataAll$LGsevenDayAnswerCnt),
family = "gaussian",
alpha = 1, # 0 for ridge regression, 1 for lasso
standardize = TRUE,
intercept = TRUE,
nfolds = 3
)
bestK <- LASSO_BestK_LM$lambda.min
plot(LASSO_BestK_LM)
cat("best k is ", bestK, "\n")
LASSO_MOD_LM <- glmnet(
x = X,
y = as.matrix(dataAll$LGsevenDayAnswerCnt),
family = "gaussian",
alpha = 1,
lambda = bestK,
standardize = TRUE,
intercept = TRUE
)