【问题标题】:Error in Random Forest: "Need at least two classes to do classification"随机森林中的错误:“需要至少两个类来进行分类”
【发布时间】:2013-06-24 14:21:24
【问题描述】:

我正在尝试创建一个物种分布模型,并且我正在遵循 Robert J. Hijmans 和 Jane Elith 的指南“使用 R 进行物种分布建模”。

一切似乎都很好,但是当我尝试运行 RandomForest 时,我收到以下错误消息:

"Need at least two classes to do classification". 

我使用的代码是:

library(randomForest)
model <- factor (pa) ~ Bio3 + Bio2 + Bio16 + Bio11 + aspect + depth + dem + my_epikrat + corine_2000
rfabies <- randomForest(model, data=envtrain, na.action=na.omit, ntrees=1000)


Error in randomForest.default(m, y, ...) :
  Need at least two classes to do classification.

什么可能导致这个问题?谁能帮帮我?

【问题讨论】:

  • 检查pa 至少有两个不同的值,尤其是在省略缺失值之后。

标签: r regression modeling prediction random-forest


【解决方案1】:

问题是在将pa 转换为因子后,您只有一个级别。很可能,您只有存在。

您可以通过以下方式检查:

table(factor(envtrain$pa))

如果您只有在场,则需要生成伪缺席。对于随机森林,建议使用与存在相同数量的伪缺失 here

【讨论】:

    猜你喜欢
    • 2013-12-12
    • 2014-10-13
    • 2019-09-05
    • 2013-09-22
    • 2018-02-18
    • 2020-02-02
    • 2018-05-20
    • 2016-05-25
    • 2015-09-23
    相关资源
    最近更新 更多