问题描述
文档(如果我没看错的话)说,如果随机森林预测函数遇到某些观测值的NA预测因子,则会产生NA预测.
The documentation (If I'm reading it correctly) says that the random forest predict function produces NA predictions if it encounters NA predictors for certain observations.
但是,如果我尝试在预测变量中使用某些NA的数据集上使用预测函数[2688中有7个观察结果中的NA],则会遇到以下错误情况,并且预测失败.
However, if I try to use the predict function on a dataset with some NA's in predictors [NA's in 7 observations out of 2688] I encounter the following error condition, and prediction fails.
如果可能的话,我想避免一些混乱的解决方法.
There is a slightly messy work-around that I would like to avoid if possible.
我在做/读错东西吗?它与"inherits from randomForest.formula"
子句有什么关系吗?
Am I doing/reading something wrong? Does it have to do something with the "inherits from randomForest.formula"
clause?
推荐答案
使用文档中的一些示例:
Using some examples from the documentation:
set.seed(1)
x <- data.frame(x1=gl(32, 5), x2=runif(160), y=rnorm(160))
rf1 <- randomForest(x[-3], x[[3]], ntree=10)
> inherits(rf1,"randomForest.formula")
[1] FALSE
> iris.rf <- randomForest(Species ~ ., data=iris, importance=TRUE,
proximity=TRUE)
> inherits(iris.rf,"randomForest.formula")
[1] TRUE
因此,您可能在未使用公式界面适合您的模型的情况下调用了randomForest
.
So you probably called randomForest
without using the formula interface to fit your model.
这篇关于R-随机森林预测因预测变量中的NA而失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!