On Sat, Feb 24, 2018 at 01:16:27PM -0600, Gary Black wrote: > Hi All, > > I'm a newbie and have two questions. Please pardon me if they are very basic. > > > 1. I'm using a regression tree to predict the selling prices of 10 new > records (homes). The following code is resulting in an error message: pred > <- predict(model, newdata = outOfSample[, -6]) > > The error message is: > > Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = > attr(object, : > factor Sq. Feet has new levels 1375, 1421, 1547, 1621, 1868, 2211, 2265, > 2530, 2672, 3365 >
Seems to me that variable 'Sq. Feet' is being encoded as a factor instead of having numerical values. When you train, the model sees a series of values that understands as categorical, and when you try to predict it is encountering some different categories and it doesn't know what to do with them. As that variable is most probably numeric, it should be read as such. You can try converting it on both your train and test datasets. Cheers, JMM. -- José María Mateos https://rinzewind.org/blog-es || https://rinzewind.org/blog-en ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.