Error when using rpart to create a classification tree

1.1k views Asked by At

I made a tree classification model with the package 'rpart' and met some problems.

This is my code, coupled with errors and output.

#Using the rpart package generate a classification tree predicting certified from the other variables in the M1 data frame.
c.tree1 = rpart(factor(certified)~., method="class", data=M1)

'Error in plot.rpart(tree, uniform = TRUE, branch = 0.2, compress = TRUE, : fit is not a tree, just a root'

#Check the results from the classifcation tree using the printcp() command
printcp(c.tree1)

Classification tree:
rpart(formula = factor(certified) ~ ., data = M1, method = "class")

Variables actually used in tree construction:
character(0)

Root node error: 204/1000 = 0.204

n= 1000 

  CP nsplit rel error xerror xstd
1  0      0         1      0    0

#Plot your tree
post(c.tree1,file='',title='Tree1')

'Error in plot.rpart(tree, uniform = TRUE, branch = 0.2, compress = TRUE, : fit is not a tree, just a root'

Does anyone know why this has happened and how to solve this problem? Thanks very much.

0

There are 0 answers