0
$\begingroup$

I am trying to create a decision tree using the rpart package in R. To arrive at the optimal depth for the tree, I am using the plotcp function in the package (which provides the cross validated error rate for various complexity parameter thresholds).

Ideally, you would expect the error to be very high for high values of cp, which will then gradually decrease before increasing again or flattening out (bias-variance trade-off)

However, the plot that I am getting is almost a straight line and as such implies that my optimal tree should have zero nodes. That should not be possible, as I do have a few strong/moderately strong predictors in my data set (and this relationship gets picked up when I try other models like logistic/conditional inference trees (party package) and the resulting models are reasonably accurate).

I am pasting the cp plot that I got below. Any thoughts on what the issue could be?

enter image description here

$\endgroup$
2
$\begingroup$

I believe I figured out the problem. Essentially, my classes were imbalanced (25% Event & 75% Non-Event) And none of the nodes had a probability > 50% for the event class. Hence all the nodes were being classified as - "Non Event", irrespective of the CP values (and hence the flat line in the plot)

All I needed to do was to add a loss matrix to bring down the probability threshold for a node to be considered as an "Event" node. The subsequent CP plots that I got was in line with the Bias-variance tradeoff that one would expect.

Thanks!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.