首页 > 解决方案 > 用插入符号构建模型。警告信息:使用 2 级因子作为结果列

问题描述

我正在尝试使用 LASSO 进行分类。expand_combined_6ml_ 的值为 0 或 1。

我写了这段代码,我收到了这个错误消息。如何修改我的代码以使用 2 级因子作为警告提及。

set.seed(15)
model1 <- train(expansion_combined_6ml_33 ~ .,
                data=train_data1.2,
                preProcess=c("center","scale"),
                method="glmnet",
                family = "binomial",
                tuneGrid=expand.grid(alpha=1, lambda=lambda_vector),
                trcontrol=ctrlspecs,
                na.action=na.omit)


Warning messages:
1: In train.default(x, y, weights = w, ...) :
  You are trying to do regression and your outcome only has two possible values Are you trying to do classification? If so, use a 2 level factor as your outcome column.
2: In nominalTrainWorkflow(x = x, y = y, wts = weights, info = trainInfo,  :
  There were missing values in resampled performance measures.

所有代码如下,

set.seed(15)
index<-createDataPartition(data1.2$expansion_combined_6ml_33, p=.8, list=FALSE, times=1)
train_data1.2 <- data1.2[index,]
test_data1.2 <-data1.2[-index,]
ctrlspecs<-trainControl(method="cv", number=10, savePredictions="all")
lambda_vector <- 10^seq(5, -5, length=500)
set.seed(15)
model1 <- train(expansion_combined_6ml_33 ~ .,
                data=train_data1.2,
                preProcess=c("center","scale"),
                method="glmnet",
                family = "binomial",
                tuneGrid=expand.grid(alpha=1, lambda=lambda_vector),
                trcontrol=ctrlspecs,
                na.action=na.omit)
model1$bestTune$lambda 

coef(model1$finalModel,model1$bestTune$lambda)

标签: rr-caret

解决方案


推荐阅读