Error in tuneRF in R in if (n == 0) stop("data (x) has 0 rows") : argument is of length zero

Avi

I would like to optimize the values of hyperparameters of ctree() (randomforest). I use the function tuneRF. I get the following error:

Error in if (n == 0) stop("data (x) has 0 rows") : 
  argument is of length zero

Here is my code:

library(party)
library(randomForest)
library(mlbench)
dat1 <- fread('https://archive.ics.uci.edu/ml/machine-learning-databases/abalone/abalone.data',stringsAsFactors=T)

## split data to train and test
set.seed(123)
dat1 <- subset(dat1, !is.na(V1))
smp_size =92
train_ind <- sample(seq_len(nrow(dat1)), size = smp_size)
train <- dat1[train_ind, ]
test <- dat1[-train_ind, ]

ct <- ctree(V1 ~ ., data = train)

And here is my trial for finding the mtry

bestmtry <- tuneRF(train$V1,  train[V2:V9], stepFactor=1.5, improve=1e-5, ntree=500)
Julius Vainora

There were a couple of issues,

bestmtry <- tuneRF(train[, V2:V9], train$V1, stepFactor = 1.5, improve = 1e-5, ntree = 500)

works.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Error in if ((dimension < 1) | (dimension > n)) stop("wrong embedding dimension") : argument is of length zero

if statement in R. Error argument is of length zero

r if statement meet error: argument is of length zero

"Argument of length zero" in R

Error in if (nrow(chan) == 0) { : argument is of length zero in slackr Package

Get rid of 'argument is of length zero' error message in R console

error message in R : if (nomZ %in% coded) { : argument is of length zero

R - argument is of length zero in if statement

R argument of length zero in if statement

Declaration with argument length zero in R

R CMD build . fails: "argument is of length zero"

R marmap getNOAA.bathy Error in if (ncol(x) == 3 & !exists("bathy", inherits = FALSE)) { : argument is of length zero

How to address the Error argument of length 0

Error in 1:x : argument of length 0

R plot.gam Error "Error in 1:object$nsdf : argument of length 0"

R: "argument is of length 0" (empty plot)

Is it possible for an argv[n] argument to have a length of 0?

Receiving error while trying to loop an if condition: "argument is of length zero"

Error when iterating for loop over columns: "argument is of length zero"

Rvest 'Error in if (is_http) { : argument is of length zero' for specific websites -- why?

Getting an error saying argument is of length zero when looping

R: Error in a Loop, replacement has length zero

'replacement has length zero' error in R

Error: Replacement has length zero R

Why is R saying "argument is of length zero" and how can I fix this?

R argument is of length zero when using names(vector) in IF statement

In R Shiny, how to eliminate "Warning: Error in if: argument is of length 0" from running reactive function?

Function to get the determinant of a NxN matrix using laplace expansion in R (Error: argument of length 0)

Json to Dataframe: error: error in 1:nrow(test) : argument of length 0