Decision tree using rpart for factor returns only the first node

35 views Asked by At

I am trying to make a decision tree using rpart function in r. I have the y variable "outcome" and 4 variables as x. All of them are factors. Every tree I tried to make returns only the first node when I plot it.

Here is the code:

library(rpart)
library(rpart.plot)
train<-read.csv('train.csv', head=T, sep=",", dec=".")
train$gender<-factor(train$gender)
train$hr<-factor(train$hr)
train$sbp<-factor(train$sbp)
train$dbp<-factor(train$dbp)
train$outcome<-factor(train$outcome)
model <- rpart(outcome~., data=train, method="class")
rpart.plot(model)

At model <- I tried using any other combination and not with all the variables but again I had the same problem. I also tried using numeric variables and they worked with the "outcome" variable.

0

There are 0 answers