Re: Level Order Tree Traversal of C4.5 (J48) Tree

[email protected]
Newsgroups gmane.comp.ai.weka
Message-ID <162497828349.9590.9532053570620477576@sys-mailman-prd.its.waikato.ac.nz>
Dear Professor Eibe Frank,

I have used the code from

https://www.geeksforgeeks.org/generic-tree-level-order-traversal/

and now the code adapted to Weka is:

public void LevelOrderTreeTraversal(ClassifierTree root, StringBuffer text) throws Exception {

    if (root==null){
      return;
    }
    Queue<ClassifierTree> q = new LinkedList<>();
    q.add(root);
    while (!q.isEmpty()){
      int n = q.size();
      while(n>0){
        ClassifierTree p = q.peek();
        q.remove();
        if (p.isLeaf()){
          text.append(": " + p.m_localModel.dumpLabel(0, p.m_train) + "\n");
        } else {

          for (int i = 0; i < p.m_sons.length; i++) {
            text.append(p.m_localModel.leftSide(p.m_train)+
                    p.m_localModel.rightSide(i, p.m_train)+"\n");
            q.add(p.m_sons[i]);
          }
        }
        n--;
      }
      text.append("\n");
    }
  }

with the call from the toString() method being:

LevelOrderTreeTraversal(this, text);

In this way, someone can discern the different levels of the tree.

Thank you for all your valuable help!

Cheers,

Spyros Halkidis
_______________________________________________
Wekalist mailing list -- [email protected]
Send posts to [email protected]
To unsubscribe send an email to [email protected]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.