我正在使用randomForest包中的randomForest函数来查找最重要的变量: 我的数据框叫做urban,我的响应变量是数字型的revenue。
urban.random.forest <- randomForest(revenue ~ .,y=urban$revenue, data = urban, ntree=500, keep.forest=FALSE,importance=TRUE,na.action = na.omit)
I get the following error:
Error in randomForest.default(m, y, ...) : data (x) has 0 rows
在源代码中,它与x
变量相关:
n <- nrow(x)
p <- ncol(x)
if (n == 0)
stop("data (x) has 0 rows")
但我无法理解x
是什么。
randomForest
,那么就不应该再传递y
值,因为函数会假定该公式是x
值,并且可能会出现问题。 - Rolandurban.random.forest <- randomForest(Species ~ ., data=iris, ntree=500, keep.forest = FALSE, importance = TRUE, na.action = na.omit)
- David Arenburg