[R] randomForest, 'No forest component...' error while calling Predict()

Moshe Olshansky m_olshansky at yahoo.com
Mon Jun 16 03:44:48 CEST 2008


You must use randomForest with keep.forest=TRUE - otherwise the Forest object is not saved and so no prediction can be made.


--- On Mon, 16/6/08, Jim_S <virtualreal at gmail.com> wrote:

> From: Jim_S <virtualreal at gmail.com>
> Subject: [R]  randomForest, 'No forest component...' error while calling Predict()
> To: r-help at r-project.org
> Received: Monday, 16 June, 2008, 8:13 AM
> Dear R-users,
> 
> While making a prediction using the randomForest function
> (package
> randomForest) I'm getting the following error message: 
> 
> "Error in predict.randomForest(model, newdata = CV) : 
> No forest component
> in the object"
> Here's my complete code. For reproducing this task,
> please find my 2 data
> sets attached (
> http://www.nabble.com/file/p17855119/data.rar data.rar ).
> 
> Thanks in advance for any help!
> 
>  - Jim
> 
> CT <-
> read.table("CT.txt",header=TRUE,sep="\t")
> CV <-
> read.table("CV.txt",header=TRUE,sep="\t")
> # Both CT & CV have the syntaxis X1, X2,...,X97,Y where
> all variables are
> numeric 
> x <- CT[,-98]
> y <- CT[,98]
> xtest <- CV[,-98]
> ytest <- CV[,98]
> library(randomForest)
> model <- randomForest(x ,y , xtest,
> ytest,ntree=500,mtry=32,nodesize=5,nPerm=2)
> model
> 
> #Call:
> # randomForest(x = x, y = y, xtest = xtest, ytest = ytest,
> ntree = 500,     
> mtry = 32, nodesize = 5, 
> # nPerm = 2) 
> #               Type of random forest: regression
> #                    Number of trees: 500
> #No. of variables tried at each split: 32
> #
> #          Mean of squared residuals: 0.0022117
> #                    % Var explained: -1.01
> #                       Test set MSE: 0
> #                    % Var explained: 2.61
>  
> 
> prediction <- predict(model, newdata= CT)
> #Error in predict.randomForest(model, newdata = CV) : 
> #  No forest component in the object
> # 
> -- 
> View this message in context:
> http://www.nabble.com/randomForest%2C-%27No-forest-component...%27-error-while-calling-Predict%28%29-tp17855119p17855119.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.



More information about the R-help mailing list