On Thu, 31 Jul 2008, Chua Siang Li wrote:


  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. "

That's about a level defined in the factor passed to rpart but not present in the data, not a level not present in the factor in the original data. E.g. if 'fruit' has levels apple, orange, lemon and there were no oranges in the training set. Your situation is that you asked for predictions on pears.

  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: [EMAIL PROTECTED]
  Website: www.acceval-intl.com
  This message and any attachments (the "message"...{{dropped:13}}
______________________________________________
[email protected] 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.


--
Brian D. Ripley,                  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
[email protected] 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.

Reply via email to