# How to count terminate leaves in decision tree?

3 visualizzazioni (ultimi 30 giorni)
Radoslav Vandzura il 19 Feb 2016
Modificato: per isakson il 21 Feb 2016
Hello All. I would like to ask you, exist any way how to count number of terminate leaves in decision tree? For example, I have two kinds of terminate leaves yes|no. I would like to know how many are yes and how many are no from all terminate leaves...Thank you in advance for your answer...
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

per isakson il 20 Feb 2016
Modificato: per isakson il 21 Feb 2016
"exist any way how to count number of terminate leaves in decision tree?" &nbsp This is what I found in the R2014a documentation
my_tree = fitctree(X,Y);
sum(double(not(my_tree.IsBranch)))
which returned "19" for this example (copy&pasted from the documentation).
"how many are yes and how many are no from all terminate leaves" &nbsp after some browsing of the documentation
is_leaf = not(my_tree.IsBranch);
cac = my_tree.NodeClass(is_leaf);
n_g = sum(double(strcmp( cac, 'g' )));
n_b = sum(double(strcmp( cac, 'b' )));
[ n_g, n_b, n_g+n_b ]
outputs
ans =
6 13 19
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Analysis of Variance and Covariance in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by