Closed ning-y closed 1 year ago
I have cross-posted this on StackExchange's Cross Validated.
Using the same example as above, if I change iris_outcomes
into a factor, I get a different error.
iris_outcomes
into a factoriris_outcomes <- ifelse(iris_outcomes==1, "A", "B") %>% as.factor()
> safs(
x=iris_predictors, y=iris_outcomes,
method="svmLinear", metric="ROC", iters=5,
safsControl=sa_ctrl, trControl=tr_ctrl)
Fold01 1 NA (1)
Fold01 2 NA->NA (1+1, 50.0%)Fold02 1 NA (1)
Fold02 2 NA->NA (1+1, 50.0%)Fold03 1 NA (1)
Fold03 2 NA->NA (1+1, 50.0%)Fold04 1 NA (1)
Fold04 2 NA->NA (1+1, 50.0%)Fold05 1 NA (1)
Fold05 2 NA->NA (1+0, 0.0%)Fold06 1 NA (1)
Fold06 2 NA->NA (1+1, 50.0%)Fold07 1 NA (1)
Fold07 2 NA->NA (1+0, 0.0%)Fold08 1 NA (1)
Fold08 2 NA->NA (1+0, 100.0%)Fold09 1 NA (1)
Fold09 2 NA->NA (1+1, 50.0%)Fold10 1 NA (1)
Fold10 2 NA->NA (1+1, 50.0%)Error in { : task 1 failed - "missing value where TRUE/FALSE needed"
> traceback()
5: stop(simpleError(msg, call = expr))
4: e$fun(obj, substitute(ex), parent.frame(), e$data)
3: foreach(i = seq(along = safsControl$index), .combine = "c", .verbose = FALSE,
.errorhandling = "stop") %op% {
sa_select(x[safsControl$index[[i]], , drop = FALSE], y[safsControl$index[[i]]],
funcs = safsControl$functions, sa_metric = safsControl$metric,
sa_maximize = safsControl$maximize, iters = iters, sa_verbose = safsControl$verbose,
testX = x[safsControl$indexOut[[i]], , drop = FALSE],
testY = y[safsControl$indexOut[[i]]], sa_seed = safsControl$seeds[i],
improve = safsControl$improve, Resample = names(safsControl$index)[i],
holdout = safsControl$holdout, lvl = classLevels, ...)
}
2: safs.default(x = iris_predictors, y = iris_outcomes, method = "svmLinear",
metric = "ROC", iters = 5, safsControl = sa_ctrl, trControl = tr_ctrl)
1: safs(x = iris_predictors, y = iris_outcomes, method = "svmLinear",
metric = "ROC", iters = 5, safsControl = sa_ctrl, trControl = tr_ctrl)
My bad! This error is due to a mismatch in the arguments of safs
and the value of its list argument safsControl
.
I had written:
sa_ctrl <- safsControl(
functions=caretSA, method="cv", number=10, p=0.75,
# Oops!
metric=c(internal="Accuracy", external="Accuracy"),
maximize=c(internal=TRUE, external=TRUE),
improve=20, seeds=137+(0:10),
returnResamp="all",
verbose=TRUE)
safs(
x=iris_predictors, y=iris_outcomes,
method="svmLinear", metric="ROC", iters=5,
safsControl=sa_ctrl, trControl=tr_ctrl)
But clearly the safsControl
call should have metric=c(internal="ROC", external="ROC")
instead. Making this edit fixed the error.
But this only gives ROC for the internal performance metric. In order to enable ROC for the external performance metric, I had to assign twoSummaryFunction
as sa_ctrl$functions$fitness_extern
:
sa_ctrl$functions$fitness_extern <- twoClassSummary
Making these two changes solved the issue.
Minimal dataset:
Minimal, runnable code:
Error output:
Warning output
Session Info: