【问题标题】:Error in tuneRF in R in if (n == 0) stop("data (x) has 0 rows") : argument is of length zeroif (n == 0) stop("data (x) has 0 rows") 中 R 中的 tuneRF 错误:参数长度为零
【发布时间】:2018-11-25 19:11:26
【问题描述】:

我想优化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)

【问题讨论】:

    标签: r random-forest ctree


    【解决方案1】:

    有几个问题,

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

    有效。

    【讨论】:

    • 谢谢@JuliusVainora!是不是意味着 mtry = 6 是最优值?
    • 回答这个问题,smp_size 是什么?它没有在您的示例中定义。
    • 请详细说明您在 smp_size 中的含义。我想使用我可以使用的所有超参数来提高 ctree 模型的准确性...
    • 我的意思是您的示例不可重现,因为您的代码中存在的smp_size 未定义。因此,我无法运行tuneRF 并回答您关于mtry 的问题。
    • smp_size =92 但可以更改。
    猜你喜欢
    • 2016-03-15
    • 2018-08-07
    • 1970-01-01
    • 1970-01-01
    • 2016-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-03
    相关资源
    最近更新 更多