Hello, I need to classify (i.e., export a vector with terminal node id's) new cases using a ctree (party package) model based on different cases (learning sample). I tried the where command with the following syntax:> where(tree, newdata=data2)expecting to get terminal nodes of data2 cases based on rules of tree model (data1 as learning sample). However it returned the following error message: Error in checkData(oldData, RET) : Classes of new data do not match original data Party documentation states that I can use this command both for learning sample (newdata=NULL) or new observations. What am I doing wrong? Best wishes Joao Daniel -- View this message in context: http://r.789695.n4.nabble.com/Where-command-in-ctree-party-tp3264187p3264187.html Sent from the R help mailing list archive at Nabble.com.
Hi, I'm running into the same issue. I run is.factor() on training data and validation data. All returned false. -- View this message in context: http://r.789695.n4.nabble.com/Where-command-in-ctree-party-tp3264187p4397640.html Sent from the R help mailing list archive at Nabble.com.
i run class(). Both have the same class. -- View this message in context: http://r.789695.n4.nabble.com/Where-command-in-ctree-party-tp3264187p4397693.html Sent from the R help mailing list archive at Nabble.com.
On Fri, 17 Feb 2012, josephw wrote:> i run class(). Both have the same class.Without a reproducible example it is hard to say what is going on here. All columns of the learning and the test data need to have (a) the same name, (b) the same class, (c) the same levels in case they are factors.> -- > View this message in context: http://r.789695.n4.nabble.com/Where-command-in-ctree-party-tp3264187p4397693.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. >
I was able to narrow down to a column that has different types using featurefields<-c(7, 17, 19, 20, 22, 33, 35, 36, 38, 44:132) flag <- rep(0, ncol(data)) for (i in featurefields) { flag[i] <- class(data[,i]) != class(validdata[,i]) } It is an integer class in the training data but is numeric in the validation data even though unique(valid[,88]) shows 0 and 1. -----Original Message----- From: Achim Zeileis [mailto:Achim.Zeileis at uibk.ac.at] Sent: Friday, February 17, 2012 10:51 AM To: Joseph Wang Cc: r-help at r-project.org Subject: Re: [R] "Where" command in ctree (party) On Fri, 17 Feb 2012, josephw wrote:> i run class(). Both have the same class.Without a reproducible example it is hard to say what is going on here. All columns of the learning and the test data need to have (a) the same name, (b) the same class, (c) the same levels in case they are factors.> -- > View this message in context: > http://r.789695.n4.nabble.com/Where-command-in-ctree-party-tp3264187p4 > 397693.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. >
On Fri, 17 Feb 2012, Joseph Wang wrote:> > I was able to narrow down to a column that has different types using > > featurefields<-c(7, 17, 19, 20, 22, 33, 35, 36, 38, 44:132) > flag <- rep(0, ncol(data)) > for (i in featurefields) { > flag[i] <- class(data[,i]) != class(validdata[,i]) > }A construct like which(sapply(data, class) != sapply(validdata, class)) might also help.> It is an integer class in the training data but is numeric in the > validation data even though unique(valid[,88]) shows 0 and 1.Hopefully valid[,88] <- as.integer(valid[,88]) should then resolve the problems. Z> > -----Original Message----- > From: Achim Zeileis [mailto:Achim.Zeileis at uibk.ac.at] > Sent: Friday, February 17, 2012 10:51 AM > To: Joseph Wang > Cc: r-help at r-project.org > Subject: Re: [R] "Where" command in ctree (party) > > On Fri, 17 Feb 2012, josephw wrote: > >> i run class(). Both have the same class. > > Without a reproducible example it is hard to say what is going on here. > All columns of the learning and the test data need to have (a) the same name, (b) the same class, (c) the same levels in case they are factors. > >> -- >> View this message in context: >> http://r.789695.n4.nabble.com/Where-command-in-ctree-party-tp3264187p4 >> 397693.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. >> > >