// compute average error
double expansionError = 0;
int count = 0;
for (int i=0; i<m_numFoldsPruning; i++) {
Evaluation eval;
// calculate error rate if only root node
if (expansion==0) {
m_roots[i].m_isLeaf = true;
eval = new Evaluation(test[i]);
eval.evaluateModel(m_roots[i], test[i]);
if (m_UseErrorRate) expansionError += eval.errorRate();
else expansionError += eval.rootMeanSquaredError();
count ++;
}
// make tree - expand one node at a time
else {
if (m_roots[i] == null) continue; // if the tree cannot be expanded, go to next fold
m_roots[i].m_isLeaf = false;
BFTree nodeToSplit = (BFTree)
(((FastVector)(parallelBFElements[i].elementAt(0))).elementAt(0));
if (!m_roots[i].makeTree(parallelBFElements[i], m_roots[i], train[i],
nodeToSplit.m_SortedIndices, nodeToSplit.m_Weights,
nodeToSplit.m_Dists, nodeToSplit.m_ClassProbs,
nodeToSplit.m_TotalWeight, nodeToSplit.m_Props, m_minNumObj,
m_Heuristic, m_UseGini)) {
m_roots[i] = null; // cannot be expanded
continue;
}
eval = new Evaluation(test[i]);
eval.evaluateModel(m_roots[i], test[i]);
if (m_UseErrorRate) expansionError += eval.errorRate();
else expansionError += eval.rootMeanSquaredError();
count ++;
}
}
// no tree can be expanded any more
if (count==0) break;
expansionError /=count;
errorList.addElement(new Double(expansionError));
currentError = expansionError;
if (!m_UseOneSE) {
if (currentError>previousError)
break;
}
else {
if (expansionError < minError) {
minError = expansionError;
minExpansion = expansion;
}
if (currentError>previousError) {
double oneSE = Math.sqrt(minError*(1-minError)/
data.numInstances());
if (currentError > minError + oneSE) {
break;
}
}
}
expansion ++;
previousError = currentError;
}
if (!m_UseOneSE) expansion = expansion - 1;
else {
double oneSE = Math.sqrt(minError*(1-minError)/data.numInstances());
for (int i=0; i<errorList.size(); i++) {
double error = ((Double)(errorList.elementAt(i))).doubleValue();
if (error<=minError + oneSE) { // && counts[i]>=m_numFoldsPruning/2) {
expansion = i;
break;
}
}
}
}
// build a postpruned tree
else {
FastVector[] modelError = new FastVector[m_numFoldsPruning];
// calculate error of each expansion for each fold
for (int i = 0; i < m_numFoldsPruning; i++) {
modelError[i] = new FastVector();
m_roots[i].m_isLeaf = true;
Evaluation eval = new Evaluation(test[i]);
eval.evaluateModel(m_roots[i], test[i]);
double error;
if (m_UseErrorRate) error = eval.errorRate();
else error = eval.rootMeanSquaredError();
modelError[i].addElement(new Double(error));
m_roots[i].m_isLeaf = false;
BFTree nodeToSplit = (BFTree)
(((FastVector)(parallelBFElements[i].elementAt(0))).elementAt(0));