bethatkinson / rpart

Recursive Partitioning and Regression Trees
46 stars 24 forks source link

Decision Tree leaf node assignments in rpart #47

Open wreck84 opened 1 year ago

wreck84 commented 1 year ago

I want to create a feature/column in a dataset that indicates which leaf node a record belongs to, based on the leaf node prediction. Examining the feature values and conducting a one-way anova on the leaf nodes are the main goals.

I do not understand the rpart documentation enough to see if rpart already provides that functionality. I am self-taught in R.

I tried to create a nested series of ifelse statements one at a time to make sure I didn't flub up on the syntax, but that only worked for a while. Eventually, it got to the point where I got error messages that could not be resolved. It is a very large decision tree with 16 leaf nodes.

Performing this task in R would be best, but exporting the dataset to Excel and re-importing it into R seems to be my only alternative at the moment.

I would appreciate it if someone had any suggestions on how to complete this task in R, rpart, or some other package.

RoelVerbelen commented 1 year ago

You can use the rpart.predict.leaves() function from the treeClust package. See the documentation here.