Skip to content
Prev 30063 / 398513 Next

randomForests predict problem

oups, sorry, 'newdata' needs to be specified:

R> library(mlbench)
R> library(randomForest)
R> data(Soybean)
R>
R> test <- sample(1:683, 150, replace=FALSE)
R>
R> sl <- Soybean[-test,]
R> st <- Soybean[test,]
R>
R> sb.rf <- randomForest(Class~., data=Soybean, subset=-test)
R> st <- st[complete.cases(st),]
R> dim(st)
[1] 115  36
R> sb.rf.pred <- predict(sb.rf, newdata=st)
R> length(sb.rf.pred)
[1] 115
R> sb.rf.pred[1:10]
 [1] brown-spot          alternarialeaf-spot brown-spot
 [4] alternarialeaf-spot brown-spot          anthracnose
 [7] bacterial-pustule   bacterial-blight    alternarialeaf-spot
[10] frog-eye-leaf-spot
19 Levels: 2-4-d-injury alternarialeaf-spot anthracnose ...
rhizoctonia-root-rot

looks like an NA problem, anyway.

Torsten