randomForest错误:预测变量中不允许NA(但数据中没有NA)

时间:2014-05-30 17:01:03

标签: r machine-learning bioinformatics random-forest na

所以我试图在R中运行'genie3'算法(ref: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()'函数,通过更改此行来省略NAs(以防万一):

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的代码运行,如何显示此错误?

1 个答案:

答案 0 :(得分:1)

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

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

仔细检查行,就像我的情况一样,行没有值&#34; ,,,,,,,,,&#34; (在我的文件列中,预测变量是逗号在射频运行时显示为NA。

您可以删除这些行。

谢谢

相关问题