'Error in cut.default(y, breaks, include.lowest = TRUE) : invalid number of intervals
I use Iris dataset to build a neuralnet model.
My goal is to use the caret package from R to predict the species class of various Iris flowers.
I try to train model with leave one out cross validation by caret.
formula.bpn <- setosa+versicolor+virginica ~ Sepal.Length+Sepal.Width+Petal.Length+Petal.Width
smp.size <- floor(0.8*nrow(data))
set.seed(542)
train.ind <- sample(seq_len(nrow(data)), smp.size)
train <- data[train.ind,]
test <- data[-train.ind,]
train.control <- trainControl(method="LOOCV",
search="grid",
verboseIter=FALSE,
returnData=TRUE,
returnResamp="final",
savePredictions="final",
# classProbs=TRUE,
selectionFunction="best",
indexFinal=NULL,
allowParallel=TRUE
)
model <- train(form=formula.bpn,
data=train,
method="neuralnet",
metric="RMSE",
maximize=FALSE,
trControl=train.control,
tuneGrid=expand.grid(.layer1=c(1:4), .layer2=c(0:4), .layer3=c(0)),
na.action=na.omit,
startweights=NULL,
algorithm="rprop+", # resilient backpropagation with weight backtracking
err.fct="sse",
act.fct="logistic",
threshold=0.01,
stepmax=5e10,
linear.output=FALSE
)
But I got the error : Error in cut.default(y, breaks, include.lowest = TRUE) : invalid number of intervals
This is the traceback :
11: stop("invalid number of intervals")
10: cut.default(y, breaks, include.lowest = TRUE)
9: cut(y, breaks, include.lowest = TRUE)
8: createFolds(outcome, n, returnTrain = TRUE)
7: make_resamples(trControl, outcome = y)
6: with_preserve_seed({
set_seed(list(seed = seed, rng_kind = rng_kind))
code
})
5: withr::with_seed(rs_seed, make_resamples(trControl, outcome = y))
4: train.default(x, y, weights = w, ...)
3: train(x, y, weights = w, ...)
2: train.formula(form = formula.bpn, data = train, method = "neuralnet",
metric = "RMSE", maximize = FALSE, trControl = train.control,
tuneGrid = expand.grid(.layer1 = c(1:4), .layer2 = c(0:4),
.layer3 = c(0)), na.action = na.omit, startweights = NULL,
algorithm = "rprop+", err.fct = "sse", act.fct = "logistic",
threshold = 0.01, stepmax = 5e+10, linear.output = FALSE)
1: train(form = formula.bpn, data = train, method = "neuralnet",
metric = "RMSE", maximize = FALSE, trControl = train.control,
tuneGrid = expand.grid(.layer1 = c(1:4), .layer2 = c(0:4),
.layer3 = c(0)), na.action = na.omit, startweights = NULL,
algorithm = "rprop+", err.fct = "sse", act.fct = "logistic",
threshold = 0.01, stepmax = 5e+10, linear.output = FALSE)
If I set form=setosa ~ Sepal.Length+Sepal.Width+Petal.Length+Petal.Width
or versicolor ~ Sepal.Length+Sepal.Width+Petal.Length+Petal.Width
or virginica ~ Sepal.Length+Sepal.Width+Petal.Length+Petal.Width
, then train() can be performed normally.
How can I fix this error ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|