randomForests predict problem
Hello everybody, I'm testing the randomForest package in order to do some simulations and I get some trouble with the prediction of new values. The random forest computation is fine but each time I try to predict values with the newly created object, I get an error message. I thought I was because NA values in the dataframe, but I cleaned them and still got the same error. What am I doing wrong ?
> library(mlbench) > library(randomForest) > data(Soybean) > test <- sample(1:683, 150, replace=F) > sb.rf <- randomForest(Class~., data=Soybean[-test,]) > sb.rf.pred <- predict(sb.rf, Soybean[test,])
Error in matrix(t1$countts, nr = nclass, nc = ntest) :
No data to replace in matrix(...)
try R> test <- sample(1:683, 150, replace=FALSE) R> R> st <- Soybean[test,] R> R> sb.rf <- randomForest(Class~., data=Soybean, subset=-test) R> sb.rf.pred <- predict(sb.rf, data=st) R> R> sb.rf.pred[1:10] [1] diaporthe-stem-canker diaporthe-stem-canker diaporthe-stem-canker [4] diaporthe-stem-canker diaporthe-stem-canker diaporthe-stem-canker [7] diaporthe-stem-canker charcoal-rot charcoal-rot [10] charcoal-rot 19 Levels: 2-4-d-injury alternarialeaf-spot anthracnose ... rhizoctonia-root-rot Torsten
I did it the same way with rpart and all worked fine :
> library(rpart) > sb.rp <- rpart(Class~., data=Soybean[-test,]) > sb.rp.pred <- predict(sb.rp, Soybean[test,], type="class")
Thank you all for any advice you can give to me. -- Ir. Yves Brostaux - Statistics and Computer Science Dpt. Gembloux Agricultural University 8, avenue de la Facult? B-5030 Gembloux (Belgium) T?l : +32 (0)81 62 24 69 E-mail : brostaux.y at fsagx.ac.be Web : http://www.fsagx.ac.be/si/
______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help