[R] predict rpart: new data has new level
Chua Siang Li
siang.li.chua at acceval-intl.com
Thu Jul 31 05:37:16 CEST 2008
Hi. I uses rpart to build a regression tree. Y is continuous. Now, I try
to predict on a new set of data. In the new set of data, one of my x (call
Incoterm, a factor) has a new level.
I wonder why the error below appears as the guide says "For factor
predictors, if an observation contains a level not used to grow the tree, it
is left at the deepest possible node and frame$yval at the node is the
prediction. "
Many thanks.
> mod <- rpart(y~., data=data.frame(y=y,x=x), method="anova",
+ cp=0.05, minsplit=100, minbucket=50, maxdepth=5)
> predictLost <- predict(mod, newdata=data.frame(y=yLost, x=xLost),
type="vector")
Error in model.frame.default(Terms, newdata, na.action = act, xlev =
attr(object, :
factor 'x.Incoterm' has new level(s) MTD
----
Chua Siang Li
Consultant - Operations Research
Acceval Pte Ltd
Tel: 6297 8740
Email: siang.li.chua at acceval-intl.com
Website: www.acceval-intl.com
This message and any attachments (the "message"...{{dropped:13}}
More information about the R-help
mailing list