Wow! Fantastic, i didn't knew it would work that easily for calculating the number of nodes.

My first question was actually intend to calculate the number of nodes the pruning algorithm based on each iteration:

C45 Pruning Algorithm from weka
        if (Utils.smOrEq(errorsLeaf, errorsTree + 0.1)
                && Utils.smOrEq(errorsLeaf, errorsLargestBranch + 0.1)) {
           ////Calculate the number of Prune nodes
            m_sons = null;
            m_isLeaf = true;
            m_localModel = new NoSplit(localModel().distribution());
            return;
        }

        // Decide if largest branch is better choice than whole subtree.
        if (Utils.smOrEq(errorsLargestBranch, errorsTree + 0.1)) {
            ////Calculate the number of Prune nodes 
            largestBranch = son(indexOfLargestBranch);
            m_sons = largestBranch.m_sons;
            m_localModel = largestBranch.localModel();
            m_isLeaf = largestBranch.m_isLeaf;
            newDistribution(m_train);
            prune();
        }

However, i don't think it's necessary anymore as i will be able to get the number of nodes before and after pruning.
Thank you very much =]

On Mon, Aug 20, 2018 at 6:17 AM Eibe Frank <eibe@waikato.ac.nz> wrote:
I don’t really understand your first question, but you can establish the difference in the number of nodes before and after pruning quite easily. Here is a modified version of buildClassifier() in C45PruneableClassifierTree:

public void buildClassifier(Instances data) throws Exception {

  // remove instances with missing class
  data = new Instances(data);
  data.deleteWithMissingClass();

 buildTree(data, m_subtreeRaising || !m_cleanup);

 System.err.println("Nodes before pruning: " + numNodes());

 if (m_collapseTheTree) {
   collapse();
 }
 if (m_pruneTheTree) {
   prune();
 }

 System.err.println("Nodes after pruning: " + numNodes());

  if (m_cleanup) {
   cleanup(new Instances(data, 0));
 }
}

Cheers,
Eibe

> On 17/08/2018, at 5:56 PM, chew yee jian <chewyeejian@gmail.com> wrote:
>
> In C45PruneableClassifierTree [under J48 decision tree], function public void prune()
>
> Is it possible to calculate the number of prune nodes and leaves on each pruning iteration?
>
> On each pruning iteration, i am able to get the number of nodes and leaves for all of the child.
>
> public static int NumPruneNodes;
> for(int k=0; k<m_sons.length; k++){
> NumPruneNodes = NumPruneNodes + son(k).numNodes();
> }
> //m_root.numNodes() does not work here
>
> However, i notice in ClassifierTree.java, it is possible to use m_root.numNodes(), which would result in calculating the current tree number of nodes.
>
> *I am also figuring out whether is it possible to record the number of nodes before a pruning begin, in order for me to generate the difference for number of nodes (before pruning and after pruning).
>
>
>
> _______________________________________________
> Wekalist mailing list
> Send posts to: Wekalist@list.waikato.ac.nz
> List info and subscription status: https://list.waikato.ac.nz/mailman/listinfo/wekalist
> List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html

_______________________________________________
Wekalist mailing list
Send posts to: Wekalist@list.waikato.ac.nz
List info and subscription status: https://list.waikato.ac.nz/mailman/listinfo/wekalist
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html


--
Regards,
Chew Yee Jian