我想优化ctree()
( randomforest
) 的超参数值。我使用功能tuneRF
。我收到以下错误:
Error in if (n == 0) stop("data (x) has 0 rows") :
argument is of length zero
这是我的代码:
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)
这是我寻找mtry
bestmtry <- tuneRF(train$V1, train[V2:V9], stepFactor=1.5, improve=1e-5, ntree=500)