警告消息:在 method$prob(modelFit =modelFit, newdata =newdata, submodels =param) 中: kernlab 类概率计算失败;返回 NA

发布于 2025-01-16 19:35:38 字数 1646 浏览 5 评论 0原文

我收到上面的以下错误,该错误似乎与插入符号包有关。我检查了我的数据,没有任何 NA 值,因为它们在清理阶段全部被删除。 我正在尝试获取 AUC 的概率,以便与我在项目中使用的其他 ML 算法进行比较。我的代码如下:

    Cost = 2^c(1:8)

    svm.control = trainControl(
    method = "cv", # use cross validation
    number = 10, # with 10 folds,
    summaryFunction = defaultSummary,
    #classProbs = TRUE
    )


   svm.linear.grid <- expand.grid(
         C = Cost
   )


   svm.fit1 <- train( # Train a model model
       final_result ~ ., 
       data = sd.BBB.train.rose, # sd.BBB.train.rose as the training data
       method = "svmLinear", # using the linear kernel
       trControl = svm.control, # cross-validated as configured above
       preProc = c("center", "scale","nzv"), 
       verbose = FALSE,
       #metric="ROC",
       tuneGrid = svm.linear.grid # use the tuning grid created above
   )

   #roc and auc analysis 
   svm.prob <- predict(svm.fit2, newdata = sd.BBB.test[,-8], type="prob")

我的数据集的结构

  > str(sd.BBB.train.rose)
  'data.frame': 4926 obs. of  8 variables:
  $ gender              : num  0.0713 -0.0131 0.0321 -0.0881 -0.0344 ...
  $ highest_education   : num  0.0761 0.6618 0.2545 1.275 -0.2358 ...
  $ age_group           : num  -0.1609 0.023 0.0563 0.103 -0.2153 ...
  $ previous_attempts   : num  -0.0689 0.8812 -0.2724 0.9355 0.9366 ...
  $ disability          : num  -0.0664 0.2857 -0.0461 1.0651 -0.0573 ...
  $ avg_clicks          : num  0.588 4.666 4.174 3.228 3.532 ...
  $ academic_performance: num  3.95 1.39 3.51 -1.84 4.31 ...
  $ final_result        : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
 > 

非常感谢任何帮助。尊敬。

I'm getting the following error above which seems to be related to the caret package. I have checked my data and don't have any NA values as they were all removed in the cleaning stages.
I'm trying to get the probabilities for the AUC to compare against the other ML algorithms I'm using in my project. My code is as follows:

    Cost = 2^c(1:8)

    svm.control = trainControl(
    method = "cv", # use cross validation
    number = 10, # with 10 folds,
    summaryFunction = defaultSummary,
    #classProbs = TRUE
    )


   svm.linear.grid <- expand.grid(
         C = Cost
   )


   svm.fit1 <- train( # Train a model model
       final_result ~ ., 
       data = sd.BBB.train.rose, # sd.BBB.train.rose as the training data
       method = "svmLinear", # using the linear kernel
       trControl = svm.control, # cross-validated as configured above
       preProc = c("center", "scale","nzv"), 
       verbose = FALSE,
       #metric="ROC",
       tuneGrid = svm.linear.grid # use the tuning grid created above
   )

   #roc and auc analysis 
   svm.prob <- predict(svm.fit2, newdata = sd.BBB.test[,-8], type="prob")

The strsuture of my dataset is

  > str(sd.BBB.train.rose)
  'data.frame': 4926 obs. of  8 variables:
  $ gender              : num  0.0713 -0.0131 0.0321 -0.0881 -0.0344 ...
  $ highest_education   : num  0.0761 0.6618 0.2545 1.275 -0.2358 ...
  $ age_group           : num  -0.1609 0.023 0.0563 0.103 -0.2153 ...
  $ previous_attempts   : num  -0.0689 0.8812 -0.2724 0.9355 0.9366 ...
  $ disability          : num  -0.0664 0.2857 -0.0461 1.0651 -0.0573 ...
  $ avg_clicks          : num  0.588 4.666 4.174 3.228 3.532 ...
  $ academic_performance: num  3.95 1.39 3.51 -1.84 4.31 ...
  $ final_result        : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
 > 

Any help greatly appreciated. Respectfully.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最笨的告白 2025-01-23 19:35:38

如果没有可用的数据来重现错误,很难确定,但我认为如果您想获得返回的概率,则必须在 train 中指定 classProbs = TRUE代码>函数。试试这个:

svm.fit1 <- train( # Train a model model
       final_result ~ ., 
       data = sd.BBB.train.rose, # sd.BBB.train.rose as the training data
       method = "svmLinear", # using the linear kernel
       trControl = svm.control, # cross-validated as configured above
       preProc = c("center", "scale","nzv"), 
       verbose = FALSE,
       #metric="ROC",
       tuneGrid = svm.linear.grid, # use the tuning grid created above
       classProbs = TRUE
   )

It's quite difficult to be sure without having the data available to reproduce your error, but I think if you want to get the probabilities returned, you have to specify classProbs = TRUE in the train function. Try this:

svm.fit1 <- train( # Train a model model
       final_result ~ ., 
       data = sd.BBB.train.rose, # sd.BBB.train.rose as the training data
       method = "svmLinear", # using the linear kernel
       trControl = svm.control, # cross-validated as configured above
       preProc = c("center", "scale","nzv"), 
       verbose = FALSE,
       #metric="ROC",
       tuneGrid = svm.linear.grid, # use the tuning grid created above
       classProbs = TRUE
   )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文