【问题标题】:R (CARET) cannot take a sample larger than the population when 'replace = FALSE'当“replace = FALSE”时,R (CARET) 不能抽取大于总体的样本
【发布时间】:2021-01-02 19:56:07
【问题描述】:

我正在尝试使用 R 中的 CARET 包训练多项式支持向量机,并获得问题标题中所述的错误消息。我在谷歌上搜索解决方案时遇到了困难,想知道是否有人可以指导我找到解决方案。

我的代码在下面分享。

Train_CTRL <- trainControl(method = "repeatedcv", 
                           number = 10, repeats = 5)
SVM_Poly <- train(Degree~., 
                  data = Train_Set_Norm, 
                  method = "svmPoly",
                  trControl = Train_CTRL,
                  tuneLength = 1000)

错误:

sample.int(n = 1000000L, size = num_rs * nrow(trainInfo$loop) + 中的错误: 'replace = FALSE' 时不能抽取大于总体的样本

【问题讨论】:

    标签: r svm r-caret


    【解决方案1】:

    错误很简单。它表示在您的数据集中,样本数少于 1000。tuneLength 应少于数据集中每个组/类的样本数。由于您没有提供数据,我可以使用iris 数据重现您的错误,例如

    library(caret)
    
    Train_CTRL <- trainControl(method = "repeatedcv", 
                               number = 10, repeats = 5)
    SVM_Poly <- train(Species~., 
                      data = iris, 
                      method = "svmPoly",
                      trControl = Train_CTRL,
                      tuneLength = 1000)
    

    sample.int(n = 1000000L, size = num_rs * nrow(trainInfo$loop) + 中的错误: 'replace = FALSE' 时不能抽取大于总体的样本

    tuneLength = 1000 具有 10 倍交叉验证和 5 次重复将生成 1000 x 10 x 5 = 50000 个组合,这是计算密集型的。您可以在tuneLength 中使用较小的数字,例如

    SVM_Poly <- train(Species~., 
                      data = iris, 
                      method = "svmPoly",
                      trControl = Train_CTRL,
                      tuneLength = 10)
    

    【讨论】:

      猜你喜欢
      • 2016-06-19
      • 2017-06-05
      • 2017-01-03
      • 1970-01-01
      • 1970-01-01
      • 2016-02-11
      • 2014-01-18
      • 2021-12-30
      • 1970-01-01
      相关资源
      最近更新 更多