Skip to content

stack overflow and predict()

2 messages · Liaw, Andy, Ji Zhu

#
Try something like this (suppose x is the matrix of predictors in the
training set, and xtest is the same for the test set):

my.rp <- rpart(y ~ x, ...)
test.pred <- predict(my.rp, newdata=data.frame(x=I(xtest)))

Make sure the name of the variable in the data frame given to newdata
matches the name of the variable in the original formula, in this case `x',
a matrix.

HTH,
Andy
#
Hi Andy,

It works perfectly.  Thank you so much!!

Cheers,
Ji
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ji Zhu                          439 West Hall
Assistant Professor             550 East University
Department of Statistics        Ann Arbor, MI 48109
University of Michigan          (734) 936-2577 (O)
jizhu at umich.edu                 (734) 763-4676 (F)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~