使用交叉验证时,有没有办法确保每个折叠以某种方式包含至少几个真实类的实例?

问题描述 投票:0回答:1

我正在使用带有插入符号的交叉折叠验证来拟合模型:

library(caret)

## tuning & parameters
set.seed(123)
train_control <- trainControl(
  method = "cv",
  number = 5,
  savePredictions = TRUE,
  verboseIter = TRUE,
  classProbs = TRUE,
  summaryFunction = my_summary
)

linear_model = train(
  x = select(training_data, Avg_Load_Time),
  y = target,
  trControl = train_control,
  method = "glm", # logistic regression
  family = "binomial",
  metric = "ROC"
)

麻烦的是,在~5K行中我只有~120个真实案例。当通过插入符号使用GLM时,这会发出警告消息“glm.fit:拟合概率数字0或1发生”。

是否有我可以设置的参数或确保每个折叠都有一些真实案例的方法?

r logistic-regression
1个回答
2
投票

当您对数据进行混洗并且每个类都有足够的示例时,它会更容易。

如果您没有足够的示例,可以使用SMOTE(Synthetic Minority Oversampling Technique)增加少数类的大小。在R中打包smotefamily

然后,您将能够进行5或10倍交叉验证,而不会产生任何问题。

© www.soinside.com 2019 - 2024. All rights reserved.