如何使用glmnet(套索)获得预测值?

时间:2019-08-01 02:03:28

标签: r regression logistic-regression anova p-value

我能够使用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
)

0 个答案:

没有答案