0

Trying to work around Random forest in R.

rf<- randomForest(train$Loan_Status~., data=train,  mtry=5,importance=TRUE, ntree=200,na.action=rfImpute(train$Loan_Status ~., train),allowParallel=TRUE)
Andrea
  • 11,801
  • 17
  • 65
  • 72
Zyerr Dwij
  • 13
  • 1
  • 2
    What's the question? – nist Nov 23 '15 at 15:49
  • question is R error that i am getting "attempt to apply non-function" – Zyerr Dwij Nov 23 '15 at 16:02
  • this code rf<- randomForest(train$Loan_Status~., data=train, mtry=5,importance=TRUE, ntree=200,na.action=rfImpute(train$Loan_Status ~., train),allowParallel=TRUE) is ending up in error "attempt to apply non-function" – Zyerr Dwij Nov 23 '15 at 16:03
  • No, I got the error "object train not found" ;) Could you please provide a reproducable example http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Iris Nov 23 '15 at 16:15
  • Here is the full code +++++++++++++++++ train = read.csv(file.choose(),,na.strings=c("NA","")) test = read.csv(file.choose(),,na.strings=c("NA","")) library(randomForest) train$Loan_Status<-factor(as.numeric(train$Loan_Status)) train = train[,-1] set.seed(222) train$Loan_Status<-factor(as.numeric(train$Loan_Status)) rf<- randomForest(train$Loan_Status~., data=train, mtry=5,importance=TRUE, ntree=200,na.action=rfImpute(train$Loan_Status ~., train),allowParallel=TRUE) ++++ You Need to use a data file "train" and IDK how can i provide u that . – Zyerr Dwij Nov 23 '15 at 16:26
  • update your question, don't put additional code in the comments. – Heroka Nov 23 '15 at 16:56

1 Answers1

0

na.action does not work like that, it takes a function such as na.fail or na.omit as input.

Try to use rfImpute as in documented example

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)
Soren Havelund Welling
  • 1,823
  • 1
  • 16
  • 23