public int prune(double[] alphas,double[] errors,Instances test) throws Exception {
  Vector<LMTNode> nodeList;
  CompareNode comparator=new CompareNode();
  treeErrors();
  calculateAlphas();
  nodeList=getNodes();
  boolean prune=(nodeList.size() > 0);
  alphas[0]=0;
  Evaluation eval;
  if (errors != null) {
    eval=new Evaluation(test);
    eval.evaluateModel(this,test);
    errors[0]=eval.errorRate();
  }
  int iteration=0;
  while (prune) {
    iteration++;
    LMTNode nodeToPrune=Collections.min(nodeList,comparator);
    nodeToPrune.m_isLeaf=true;
    alphas[iteration]=nodeToPrune.m_alpha;
    if (errors != null) {
      eval=new Evaluation(test);
      eval.evaluateModel(this,test);
      errors[iteration]=eval.errorRate();
    }
    treeErrors();
    calculateAlphas();
    nodeList=getNodes();
    prune=(nodeList.size() > 0);
  }
  alphas[iteration + 1]=1.0;
  return iteration;
}

public int prune ( double [ ] alphas , double [ ] errors , Instances test ) throws Exception { Vector < LMTNode > nodeList ; CompareNode comparator = new CompareNode ( ) ; treeErrors ( ) ; calculateAlphas ( ) ; nodeList = getNodes ( ) ; boolean prune = ( nodeList . size ( ) > 0 ) ; alphas [ 0 ] = 0 ; Evaluation eval ; if ( errors != null ) { eval = new Evaluation ( test ) ; eval . evaluateModel ( this , test ) ; errors [ 0 ] = eval . errorRate ( ) ; } int iteration = 0 ; while ( prune ) { iteration ++ ; LMTNode nodeToPrune = Collections . min ( nodeList , comparator ) ; nodeToPrune . m_isLeaf = true ; alphas [ iteration ] = nodeToPrune . m_alpha ; if ( errors != null ) { eval = new Evaluation ( test ) ; eval . evaluateModel ( this , test ) ; errors [ iteration ] = eval . errorRate ( ) ; } treeErrors ( ) ; calculateAlphas ( ) ; nodeList = getNodes ( ) ; prune = ( nodeList . size ( ) > 0 ) ; } alphas [ iteration + 1 ] = 1.0 ; return iteration ; }
method for performing one fold in the cross - validation of the cost - complexity parameter . generates a sequence of alpha - values with error estimates for the corresponding ( partially pruned ) trees , given the test set of that fold .
