gpt4 book ai didi

随机森林错误: NA not permitted in predictors (but no NAs in data)

转载 作者:行者123 更新时间:2023-11-30 09:38:04 27 4
gpt4 key购买 nike

所以我尝试在 R 中运行“genie3”算法(引用:http://homepages.inf.ed.ac.uk/vhuynht/software.html),它使用“randomForest”方法。

我遇到以下错误:

> weight.matrix<-get.weight.matrix(tmpLog2FC, input.idx=1:4551)
Starting RF computations with 1000 trees/target gene,
and 67 candidate input genes/tree node
Computing gene 1/11805
Show Traceback

Rerun with Debug
Error in randomForest.default(x, y, mtry = mtry, ntree = nb.trees, importance = TRUE, :
NA not permitted in predictors

所以我检查了我的数据中是否存在 NA,结果没有:

> NAs<-sapply(tmpLog2FC, function(x) sum(is.na(x)))
> length(which(NAs!=0))
[1] 0

然后,我尝试通过更改此行来编辑特定的“get.weight.matrix()”函数以省略 NA(以防万一):

rf <- randomForest(x, y, mtry=mtry, ntree=nb.trees, importance=TRUE, ...)

致:

rf <- randomForest(x, y, mtry=mtry, ntree=nb.trees, importance=TRUE, na.action=na.omit)

然后我获取了代码,并通过单独调用它(并显示实际脚本)来仔细检查它是否合并了更改:

    }
target.gene.name <- gene.names[target.gene.idx]
# remove target gene from input genes
these.input.gene.names <- setdiff(input.gene.names, target.gene.name)
x <- expr.matrix[,these.input.gene.names]
y <- expr.matrix[,target.gene.name]
rf <- randomForest(x, y, mtry=mtry, ntree=nb.trees, importance=TRUE, na.action=na.omit)

但是,当尝试重新运行时,我收到相同的错误:

Error in randomForest.default(x, y, mtry = mtry, ntree = nb.trees, importance = TRUE,  : 
NA not permitted in predictors

有人遇到过类似的情况吗?关于我能做什么有什么想法吗?

提前致谢。

*编辑:按照建议,我重新运行调试:

> weight.matrix<-get.weight.matrix(tmpLog2FC, input.idx=1:4551)
Starting RF computations with 1000 trees/target gene,
and 67 candidate input genes/tree node
Computing gene 1/11805
Error in randomForest.default(x, y, mtry = mtry, ntree = nb.trees, importance = TRUE, :
NA not permitted in predictors
Called from: randomForest(x, y, mtry = mtry, ntree = nb.trees, importance = TRUE,
na.action = na.omit)
Browse[1]>
>

调试显示我怀疑的行引发了错误,但它以“na.action=na.omit”的编辑形式显示它。我更困惑了。没有 NA 的数据集,使用允许省略 NA 的代码运行,如何显示此错误?

最佳答案

您可以使用以下命令查找行列表,其中如果任何预测变量没有值,则会显示该行。

数据[!complete.cases(data),]

仔细检查行,就像在我的例子中,没有值的行",,,,,,,,,"(在我的文件中,列预测变量以逗号分隔)显示为 NA在 RF 运行时。

您可以删除该行。

谢谢

关于随机森林错误: NA not permitted in predictors (but no NAs in data),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23959810/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com