return leafString(parent); } else if (m_Info.attribute(m_Attribute).isNominal()) { text.append(m_Successors[i].toString(level + 1, this)); text.append(m_Successors[0].toString(level + 1, this)); text.append("\n"); for (int j = 0; j < level; j++) { text.append(m_Successors[1].toString(level + 1, this));
priorVar = singleVariance(totalSum, totalSumSquared, totalSumOfWeights); doSmoothing(); Utils.normalize(m_ClassProbs); } else { splits[i] = distribution(props, dists, i, sortedIndices[0][i], weights[0][i], totalSubsetWeights, data); vals[i] = gain(dists[i], priorVal(dists[i])); splits[i] = numericDistribution(props, dists, i, sortedIndices[0][i], weights[0][i], totalSubsetWeights, data, vals); double[][][][] subsetWeights = new double[numAttVals][1][data .numAttributes()][0]; splitData(subsetIndices, subsetWeights, m_Attribute, m_SplitPoint, sortedIndices[0], weights[0], data); m_Successors[i] = new Tree(); m_Successors[i].buildTree(subsetIndices[i], subsetWeights[i], data, attTotalSubsetWeights[i], attSubsetDists[i], header, minNum, minVariance, depth + 1, maxDepth); doSmoothing(); Utils.normalize(m_ClassProbs); } else {
priorVar = singleVariance(totalSum, totalSumSquared, totalSumOfWeights); doSmoothing(); Utils.normalize(m_ClassProbs); } else { splits[i] = distribution(props, dists, i, sortedIndices[0][i], weights[0][i], totalSubsetWeights, data); vals[i] = gain(dists[i], priorVal(dists[i])); splits[i] = numericDistribution(props, dists, i, sortedIndices[0][i], weights[0][i], totalSubsetWeights, data, vals); double[][][][] subsetWeights = new double[numAttVals][1][data .numAttributes()][0]; splitData(subsetIndices, subsetWeights, m_Attribute, m_SplitPoint, sortedIndices[0], weights[0], data); m_Successors[i] = new Tree(); m_Successors[i].buildTree(subsetIndices[i], subsetWeights[i], data, attTotalSubsetWeights[i], attSubsetDists[i], header, minNum, minVariance, depth + 1, maxDepth); doSmoothing(); Utils.normalize(m_ClassProbs); } else {
m_Tree = new Tree(); double trainVariance = 0; if (data.classAttribute().isNumeric()) { trainVariance = m_Tree.singleVariance(classProbs[0], totalSumSquared, totalWeight) / totalWeight; classProbs[0] /= totalWeight; m_Tree.buildTree(sortedIndices, weights, train, totalWeight, classProbs, new Instances(train, 0), m_MinNum, m_MinVarianceProp * trainVariance, 0, m_MaxDepth); m_Tree.insertHoldOutSet(prune); m_Tree.reducedErrorPrune(); m_Tree.backfitHoldOutSet();
m_Tree = new Tree(); double trainVariance = 0; if (data.classAttribute().isNumeric()) { trainVariance = m_Tree.singleVariance(classProbs[0], totalSumSquared, totalWeight) / totalWeight; classProbs[0] /= totalWeight; m_Tree.buildTree(sortedIndices, weights, train, totalWeight, classProbs, new Instances(train, 0), m_MinNum, m_MinVarianceProp * trainVariance, 0, m_MaxDepth); m_Tree.insertHoldOutSet(prune); m_Tree.reducedErrorPrune(); m_Tree.backfitHoldOutSet();
m_Successors[i].insertHoldOutInstance(inst, weight * m_Prop[i], this); m_Successors[(int) inst.value(m_Attribute)].insertHoldOutInstance( inst, weight, this); } else { m_Successors[0].insertHoldOutInstance(inst, weight, this); } else { m_Successors[1].insertHoldOutInstance(inst, weight, this);
m_Successors[i].insertHoldOutInstance(inst, weight * m_Prop[i], this); m_Successors[(int) inst.value(m_Attribute)].insertHoldOutInstance( inst, weight, this); } else { m_Successors[0].insertHoldOutInstance(inst, weight, this); } else { m_Successors[1].insertHoldOutInstance(inst, weight, this);
return leafString(parent); } else if (m_Info.attribute(m_Attribute).isNominal()) { text.append(m_Successors[i].toString(level + 1, this)); text.append(m_Successors[0].toString(level + 1, this)); text.append("\n"); for (int j = 0; j < level; j++) { text.append(m_Successors[1].toString(level + 1, this));
doSmoothing(); Utils.normalize(m_ClassProbs); } else { m_Successor.backfitHoldOutSet();
double[] help = m_Successors[i].distributionForInstance(instance); if (help != null) { for (int j = 0; j < help.length; j++) { .distributionForInstance(instance); } else { returnedDist = m_Successors[0].distributionForInstance(instance); } else { returnedDist = m_Successors[1].distributionForInstance(instance);
doSmoothing(); Utils.normalize(m_ClassProbs); } else { m_Successor.backfitHoldOutSet();
double[] help = m_Successors[i].distributionForInstance(instance); if (help != null) { for (int j = 0; j < help.length; j++) { .distributionForInstance(instance); } else { returnedDist = m_Successors[0].distributionForInstance(instance); } else { returnedDist = m_Successors[1].distributionForInstance(instance);
if (m_Attribute == -1) { text.append("N" + Integer.toHexString(Tree.this.hashCode()) + " [label=\"" + num + Utils.backQuoteChars(leafString(parent)) + "\"" + "shape=box]\n"); } else { num = m_Successors[i].toGraph(text, num, this);
if (m_Attribute == -1) { text.append("N" + Integer.toHexString(Tree.this.hashCode()) + " [label=\"" + num + Utils.backQuoteChars(leafString(parent)) + "\"" + "shape=box]\n"); } else { num = m_Successors[i].toGraph(text, num, this);
/** * Computes class distribution of an instance using the tree. * * @param instance the instance to compute the distribution for * @return the computed class probabilities * @throws Exception if computation fails */ @Override public double[] distributionForInstance(Instance instance) throws Exception { if (m_zeroR != null) { return m_zeroR.distributionForInstance(instance); } else { return m_Tree.distributionForInstance(instance); } }
/** * Computes class distribution of an instance using the tree. * * @param instance the instance to compute the distribution for * @return the computed class probabilities * @throws Exception if computation fails */ @Override public double[] distributionForInstance(Instance instance) throws Exception { if (m_zeroR != null) { return m_zeroR.distributionForInstance(instance); } else { return m_Tree.distributionForInstance(instance); } }
/** * Inserts hold-out set into tree. * * @param data the data to insert * @throws Exception if something goes wrong */ protected void insertHoldOutSet(Instances data) throws Exception { for (int i = 0; i < data.numInstances(); i++) { insertHoldOutInstance(data.instance(i), data.instance(i).weight(), this); } }
/** * Inserts hold-out set into tree. * * @param data the data to insert * @throws Exception if something goes wrong */ protected void insertHoldOutSet(Instances data) throws Exception { for (int i = 0; i < data.numInstances(); i++) { insertHoldOutInstance(data.instance(i), data.instance(i).weight(), this); } }