我在随机森林中遇到这个问题。
我有此数据框架,其中包含已经以矩阵形式为带有情感列的推文数据,我要预测。
'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 ...
这是我的随机前景,正在投掷错误。
# convert to factor
dtm.df$sentiment <- as.factor(dtm.df$sentiment)
# create a decision tree model
model_rf <- randomForest(formula = sentiment ~ .,
data = dtm.df[train,],
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 model.frame.default(terms(reformulate(attributes(Terms)$term.labels)), :
type (special) incorrect variable 'next'
如果有人可以帮助我
我找到了对我有用的解决方案。
基本上,我必须更改每个属性/功能的名称,然后将" _C"附加到最后。这已经解决了错误,随机森林工作正常。
colnames(dtm.df) <- paste(colnames(dtm.df), "_c", sep = "")
尝试使用randomForest(predictors,decision)
代替randomForest(decision~.,data=input)
。由于不需要复制数据,因此更有效且容易发生错误。
更多信息:https://stats.stackexchange.com/questions/37370/random-forest-computing-computing time-in-r-r