if (n == 0) stop("data (x) has 0 rows") 中 R 中的 tuneRF 错误:参数长度为零
Error in tuneRF in R in if (n == 0) stop("data (x) has 0 rows") : argument is of length zero
我想优化 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)
有几个问题,
bestmtry <- tuneRF(train[, V2:V9], train$V1, stepFactor = 1.5, improve = 1e-5, ntree = 500)
有效。
我想优化 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)
有几个问题,
bestmtry <- tuneRF(train[, V2:V9], train$V1, stepFactor = 1.5, improve = 1e-5, ntree = 500)
有效。