get regions from treebagger

2 views (last 30 days)
Hi,
I have a random forest, trained through treeBagger function. I need to check for the new point x, whether it results in a same region R_t for all t, with historical point x_j, for all j. Please let me know me how I can get it.
Best, Afshin
  2 Comments
Sarah Mohamed
Sarah Mohamed on 15 Sep 2017
Please provide more clarity regarding your question. Is this a classification or regression problem? What do "t" and "j" signify? Are you trying to predict whether a new point has the same response for all values of a certain predictor?
Afshin OroojlooyJadid
Afshin OroojlooyJadid on 18 Sep 2017
Hi Sarah,
Thanks for reply. This is a regression problem. "t_1,...,t_T" stands for different trees and "x_j" stands for training sample "j".
Lets assume we have 10 training samples, i.e. x_1,...,x_10, and we have trained 4 different trees in a random forest using this data. Also, assume in each of the trees there are 7 splits s_1,...,s_7 (which I called them regions before). Apparently, for any input value and for each of the training samples we know which split provides the prediction value.
Now, I have a new point "x". I am gonna check for example in tree t_3, what is the split that provides output for this sample (for example split s_6), and then also I need to know which of the training samples are felt down in this specific split (s_6) of tree t_3.
Indeed, I need a function that given X and CART tree, provides me the index of split that provides the regression prediction of those inputs.
Thanks,

Sign in to comment.

Accepted Answer

Sarah Mohamed
Sarah Mohamed on 18 Sep 2017
Thanks for the clarification!
Let me assume that you've trained an ensemble of trees using the TreeBagger function, and that this bag of trees is called 'B'.
A cell vector of the trained CompactRegressionTree subtrees is stored in the ‘Trees’ property of B. Assuming that you’ve extracted one of these trees, ‘tree1’, as follows,
tree1 = B.Trees{1};
You can determine the leaf node that determines the predicted output for the observation (or array of observations) X, using the 'predict' function:
[~,node] = predict(tree1,X)
If you would like the parent of the leaf node (e.g, the node that ‘splits’ the data), you can look up the node’s parent in the ‘Parent’ property of ‘tree1’:
splittingNode = tree1.Parent(node);

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!