随机森林错误 - nrow(x)中的错误:参数" x"缺少,没有默认值

时间:2018-03-31 08:35:42

标签: r random-forest

我遇到了随机森林抛出错误的问题。

我有这个数据框,其中包含已经是矩阵形式的推文数据,其中包含我想要预测的情感列。

'data.frame':   1000 obs. of  2155 variables:
 $ anoth                          : num  1 0 0 0 0 0 0 0 0 0 ...
 $ cancel                         : num  1 0 0 0 0 0 0 0 0 0 ...
 $ flight                         : num  2 1 0 0 0 0 0 0 1 0 ...
 $ hold                           : num  1 0 0 0 0 0 0 0 0 0 ...
 $ hour                           : num  2 0 0 0 0 0 0 0 0 0 ...
 $ ive                            : num  1 0 0 0 0 0 0 0 0 0 ...

这是我的randomForest抛出错误。

model_rf <- randomForest(data = dtm.df[train,], 
                         formula = as.factor(sentiment) ~ .,
                         importance = T, do.trace = F)

我的情绪栏基本上是正面和负面的值列表

Factor w/ 2 levels "negative","positive": 1 1 1 1 1 1 1 1 1 1 ...

[1] negative negative negative negative negative negative negative negative
   [9] negative negative negative negative negative negative negative negative

我得到的错误是

Error in nrow(x) : argument "x" is missing, with no default

如果有人能帮我解决这个问题,我真的很感激。我只是被困了

1 个答案:

答案 0 :(得分:1)

试试这个:

dtm.df$sentiment <- as.factor(dtm.df$sentiment)
model_rf <- randomForest(formula = sentiment ~ .,
                         data = dtm.df[train,], 
                         importance = T, 
                         do.trace = F)