How to set class counter / probability threshold for marking "predicted class" in R rpart

I am using the rpart function to get a decision tree to predict Owner / No Owner based on a set of variables. Below is an excerpt from the output

Node number 2: 8 observations,    complexity param=0.08333333   predicted class=non-owner  expected loss=0.125  P(node) =0.3333333
class counts:     7     1    probabilities: 0.875 0.125 

      

From the above output, you can see that Node 2 is marked as the predicted class "Non-owner" because the number of classes (probability 0.875) is 7 for the non-owner in that node. I want to change the default threshold based on which Node. To clarify, assuming the default value is 0.5 - if the probability (the number of non-owner classes is more than half of the data points) is> 0.5, then Node is designated as non-owner, but I want to change that value to 0.9 t .e. only if the number of non-owner class members is more than 9 out of 10 (ratio), Node should be marked as non-owner, otherwise the owner.

+3


source to share





All Articles