n*****5 发帖数: 61 | 1 I used rpart. The dependent variable is categorical,and the predictors
includes both categorical and continuous variables.
Here is the model I used:
y<-factor(m$Y)
b<-factor(m$B)
test<-rpart(y~a+b+c,method="class", data=m)
But it always shows "Error in yval[, 1] : incorrect number of dimensions".
Any suggestion would be greatly appreciated! | f***a 发帖数: 329 | 2 If raw dataset is "m",
y <- factor(m$Y)
b <- factor(m$B)
dat <- data.frame(m[, !(names(dat) %in% c("B","Y"))],B=b,Y=y)
dat.rp <- rpart(Y~.,dat,method="class",cp=0.001)
This should work, at least for me.
Please check if you made mistake when transforming "m$Y" "m$B" into
factor. Factor is the most naughty data type in R.
dimensions".
【在 n*****5 的大作中提到】 : I used rpart. The dependent variable is categorical,and the predictors : includes both categorical and continuous variables. : Here is the model I used: : y<-factor(m$Y) : b<-factor(m$B) : test<-rpart(y~a+b+c,method="class", data=m) : But it always shows "Error in yval[, 1] : incorrect number of dimensions". : Any suggestion would be greatly appreciated!
| n*****5 发帖数: 61 | 3 I checked the factor variables, and didn't see anything wrong. Is it because
of the control parameters?
library(rpart)
test<-read.csv("H:\CBECS\r test\test.CSV",header=TRUE,sep=",")
names(test)
dim(test)
test$frame2<-factor(test$FRAME)
test$use<-factor(test$FRMACTVC)
names(test)
summary(test$frame2)
print(test$respond)
my.control<-c(minsplit=5,cp=0.001,maxcompete=1,maxsurrogate=1,
usesurrogate=2,surrogatestyle=1)
test.rp <- rpart(respond~ frame2+region+size_scf,data=test,
method="class",control=
【在 f***a 的大作中提到】 : If raw dataset is "m", : y <- factor(m$Y) : b <- factor(m$B) : dat <- data.frame(m[, !(names(dat) %in% c("B","Y"))],B=b,Y=y) : dat.rp <- rpart(Y~.,dat,method="class",cp=0.001) : This should work, at least for me. : Please check if you made mistake when transforming "m$Y" "m$B" into : factor. Factor is the most naughty data type in R. : : dimensions".
| f***a 发帖数: 329 | 4 I didn't see anything wrong except "test$use" wasn't used.
Do you have some sample data to share? So I can run and figure out where
is wrong.
because
【在 n*****5 的大作中提到】 : I checked the factor variables, and didn't see anything wrong. Is it because : of the control parameters? : library(rpart) : test<-read.csv("H:\CBECS\r test\test.CSV",header=TRUE,sep=",") : names(test) : dim(test) : test$frame2<-factor(test$FRAME) : test$use<-factor(test$FRMACTVC) : names(test) : summary(test$frame2)
|
|