Runs a cross validation for train and prediction function.
cv(x, y, FUN, nfolds = 5, ...)matrix/data.frame, feature matrix, see ranger() for
details.
numeric/factor, classification labels, see ranger() for
details.
function function to optimize.
integer(1) number of cross validation folds.
further arguments passed to FUN.
double(1) median AUC across all cross validation splits
The function to optimize has to accept five arguments: xtrain, ytrain, xtest, ytest and ....
.rusranger <- function(xtrain, ytrain, xtest, ytest, ...) {
rngr <- rusranger(x = xtrain, y = ytrain, ...)
pred <- as.numeric(predict(rngr, xtest)$predictions[, 2L])
performance(prediction(pred, ytest), measure = "auc")@y.values[[1L]]
}
cv(iris[-5], as.numeric(iris$Species == "versicolor"), .rusranger, nfolds = 3)
#> [1] 0.995842