r - 用插入符号构建模型。警告信息:使用 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)
解决方案
推荐阅读
- php - 将自定义字段添加到 Woocommerce 产品快速编辑管理面板
- android-studio - 如何解决此问题以使计算正确?
- swift - FileManager.moveItem 的问题
- ios - Fastlane Match 奇怪的旧版本问题
- python - 使用 python 网页抓取下载 iframe 内容
- flutter - Dart:将 CSV 文件转换为 List 时将“null”字符串更改为 null
- python - Keras 中连接多输入深度神经网络的正确最后一层是什么?
- excel - 在相同的 ms excel/open office cals 中的两个数组之间插入正确的值,并带有重复项
- c++ - 使用基于范围的 for 循环的 TAR 存档迭代
- javascript - 无法将对象数组作为单独的文档写入 Firestore 集合