【问题标题】:Random Forest error - Error in nrow(x) : argument "x" is missing, with no default随机森林错误 - nrow(x) 中的错误:缺少参数“x”,没有默认值
【发布时间】:2018-09-10 04:06:41
【问题描述】:

我遇到了随机森林引发错误的问题。

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

'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 ...

这是我抛出错误的随机森林。

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

如果有人能帮我解决这个问题,我将不胜感激。我只是卡住了

【问题讨论】:

    标签: r random-forest


    【解决方案1】:

    试试这个:

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

    【讨论】:

    • 为了将来的参考,不要强制模型公式本身的任何东西,它直到现在才起作用
    • 谢谢@Ayush,这是一个教训。我遇到了另一个问题,但我会将其作为另一个问题发布。
    猜你喜欢
    • 2017-12-09
    • 2020-07-04
    • 1970-01-01
    • 2022-08-07
    • 1970-01-01
    • 2021-09-17
    • 2016-06-08
    • 1970-01-01
    相关资源
    最近更新 更多