0

My code for the predict function is as following:

predict(Flaw.rf, newdata = newtest[-grep("Product", colnames(newtest))], 
        type="prob")

When I get rid of the type="prob" there is no problem. And if I change the product to just 2, there is also no problem. However, when the product is multi-classes and I apply type="prob", there is something wrong. It says undefined columns selected

Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453
周瑜琪
  • 1
  • 1
  • 1
    Help us help you by supplying a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). That is, data and code that we can run to reproduce and, hopefully, fix the error your getting. For starters, should `newtest[-grep("Product",colnames(newtest))]` be `newtest[ , -grep("Product",colnames(newtest))]`? (Although you don't need to remove any columns from your test data in order run it through the `predict` function.) – eipi10 Jun 30 '15 at 15:44
  • I can't reproduce this with `data(iris);` `set.seed(111);` `ind <- sample(2, nrow(iris), replace = TRUE, prob=c(0.8, 0.2));` `iris.rf <- randomForest(Species ~ ., data=iris[ind == 1,]);` `predict(iris.rf, iris[ind == 2,], type = "prob")`. (With apologies for the crap formatting in here.) – Gavin Simpson Jun 30 '15 at 15:55
  • but I can't paste pictures for the reason of the reputation.... – 周瑜琪 Jun 30 '15 at 17:05
  • No need for pictures, just post a reproducible example (data + code that reproduces your error). – eipi10 Jun 30 '15 at 17:29

0 Answers0