R error: attempt to apply non-function , randomForest , rfImpute

R error: attempt to apply non-function , randomForest , rfImpute

尝试解决 R 中的随机森林问题。

rf<- randomForest(train$Loan_Status~., data=train,  mtry=5,importance=TRUE, ntree=200,na.action=rfImpute(train$Loan_Status ~., train),allowParallel=TRUE)

na.action 不是那样工作的,它需要一个函数,例如 na.fail 或 na.omit 作为输入。

尝试使用记录示例中的 rfImpute

data(iris)
iris.na <- iris
set.seed(111)
## artificially drop some data values.
for (i in 1:4) iris.na[sample(150, sample(20)), i] <- NA
set.seed(222)
iris.imputed <- rfImpute(Species ~ ., iris.na)
set.seed(333)
iris.rf <- randomForest(Species ~ ., iris.imputed)
print(iris.rf)