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

[email protected]
Newsgroups gmane.comp.ai.weka
Message-ID <162495661083.9590.2835027250498270708@sys-mailman-prd.its.waikato.ac.nz>
I include the code together with some changes. First the method:

private void dumpTreeLevelOrder(Instances root, StringBuffer text){

    if (root==null)
      return;

    Queue<Instances> q =new LinkedList<>();
    q.add(root);
    int height=1;
    while(!q.isEmpty()){
      for (int k=0; k<height; k++)
        text.append("|  ");
      int n = q.size();
      while (n>0){
        Instances p = q.peek();
        q.remove();
        text.append(m_localModel.leftSide(p));
        text.append(m_localModel.rightSide(1, p)+" ");
        for (int i=0; i<m_sons.length; i++)
          q.add(m_sons[i].m_train);
        n--;
      }
      height++;
      text.append("\n");
    }

  }

And next the call from the toString() method:

dumpTreeLevelOrder(m_train, text);

Any help would be valuable!

Thank you in advance,

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.