Getting error message when predicting Random forest AUC

I am using the r package caret and ranger to develop a classifier to predict the risk of dying, but I am having trouble calculating AUC:

I am aware that I need to set probability = TRUE when training the model, however, I get an error, and I cant run the model.

My code (I work from a remote server that doesn't allow for me to copy from it, so I will write it out manually):

set.seed(40)

control.data <- trainControl(method="cv", number=10, sampling ="up", VerboseIter= TRUE)

rfGrid <- expand.grid(
.mtry=2:6,
.splitrule="gini",
.min.node.size=c(500))

fit.dataup <- train(mort_30 ~ C_SEX+V_AGE+Hemoglobin+Thrombocytes+Leukocytes+CRP,
data=data.train,
method="ranger",
max.depth=10,
num.trees=500,
trControl=control.data,
tuneGrid=rfGrid,
importance="impurity",
probability = TRUE,
verbose=TRUE)

Then I get this error message when trying to run it:

Model fit failed for Fold01: mtry=2, splitrule=gini, min.node.size=500 Error in ranger::ranger(dependent.variable.name = ".outcome", data =x,: formal argument "probability" matched by multiple actual arguments

What am I doing wrong?

caret train expects that if you want class probabilities then you will add classProbs=TRUE to your trainControl.
example

set.seed(40)
library(caret)
library(ranger)
control.data <- trainControl(method="cv", number=10, sampling ="up", verboseIter= TRUE,
                             classProbs = TRUE)

rfGrid <- expand.grid(
  .mtry=2:3,
  .splitrule="gini",
  .min.node.size=c(5))

(fit.dataup <- train(Species ~ . ,
                    data=iris,
                    method="ranger",
                    max.depth=10,
                    num.trees=500,
                    trControl=control.data,
                    tuneGrid=rfGrid,
                    importance="impurity",
                    verbose=TRUE))


(p1 <- predict(fit.dataup,
              newdata = iris,
              type = "prob"))

2 Likes

Thank you so much! It worked perfectly.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.