Note that there are some explanatory texts on larger screens.

plurals
  1. POSearch for corresponding node in a regression tree using rpart
    text
    copied!<p>I'm pretty new to R and I'm stuck with a pretty dumb problem.</p> <p>I'm calibrating a regression tree using the <strong>rpart</strong> package in order to do some classification and some forecasting.</p> <p>Thanks to R the calibration part is easy to do and easy to control.</p> <pre><code>#the package rpart is needed library(rpart) # Loading of a big data file used for calibration my_data &lt;- read.csv("my_file.csv", sep=",", header=TRUE) # Regression tree calibration tree &lt;- rpart(Ratio ~ Attribute1 + Attribute2 + Attribute3 + Attribute4 + Attribute5, method="anova", data=my_data, control=rpart.control(minsplit=100, cp=0.0001)) </code></pre> <p>After having calibrated a big decision tree, I want, for a given data sample to find the corresponding cluster of some new data (and thus the forecasted value).<br> The <code>predict</code> function seems to be perfect for the need.</p> <pre><code># read validation data validationData &lt;-read.csv("my_sample.csv", sep=",", header=TRUE) # search for the probability in the tree predict &lt;- predict(tree, newdata=validationData, class="prob") # dump them in a file write.table(predict, file="dump.txt") </code></pre> <p>However with the <code>predict</code> method I just get the forecasted ratio of my new elements, and I can't find a way get the <strong>decision tree leaf</strong> where my new elements belong.</p> <p>I think it should be pretty easy to get since the predict method <strong>must</strong> have found that leaf in order to return the ratio.</p> <p>There are several parameters that can be given to the predict method through the <code>class=</code> argument, but for a regression tree all seem to return the same thing (the value of the target attribute of the decision tree)</p> <p>Does anyone know how to get the corresponding node in the decision tree?</p> <p>By analyzing the node with the <code>path.rpart</code> method, it would help me understanding the results.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload