2

我正在尝试使用 randomForest 中的 predict() 函数来预测四种数据缺乏物种的类别。我已经在我的原始数据上运行 RF 并创建了一个 RF 对象,然后我想用它来预测新数据的类别。

我正在使用的代码是:

# original data set "procellminvar" 
# DD sp only "procelldd"

#run RF on original data set

    procellminvar$current.red.list<-factor(procellminvar$current.red.list)
    procell6<-procellminvar[,6:80]
    procell6.imputed<-rfImpute(current.red.list~.,procell6)
    procellminvar.rf<-randomForest(current.red.list~., procell6.imputed, votes=true, importance=TRUE, ntree=1000)
    round(importance(procellminvar.rf),2)

#run prediction using original data and new data (DD sp only)

    predict(procellminvar.rf, procelldd)

RF 运行良好,但是当我尝试运行 predict 时,我收到一条错误消息:

predict(procellminvar.rf, procelldd)
# Error in eval(expr, envir, enclos) : object 'subpop' not found

我不明白为什么。有人可以简单地向我解释我在这里做错了什么吗?

4

1 回答 1

1

I think the problem is that you're running the predict on the full dataset but you are not using the full dataset in the training. Nor are you using the original variables. So you need to make sure that each variable you are using in the training also is present in the test data.

于 2013-11-14T19:20:10.297 回答