Runs a cross validation for train and prediction function.

cv(x, y, FUN, nfolds = 5, ...)

Arguments

x

matrix/data.frame, feature matrix, see ranger() for details.

y

numeric/factor, classification labels, see ranger() for details.

FUN

function function to optimize.

nfolds

integer(1) number of cross validation folds.

...

further arguments passed to FUN.

Value

double(1) median AUC across all cross validation splits

Note

The function to optimize has to accept five arguments: xtrain, ytrain, xtest, ytest and ....

Examples

.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