@Test public void testPrune() { System.out.println("USPS"); DecisionTree model = DecisionTree.fit(USPS.formula, USPS.train, SplitRule.ENTROPY, 20, 3000, 1); System.out.println(model); double[] importance = model.importance(); for (int i = 0; i < importance.length; i++) { System.out.format("%-15s %.4f%n", model.schema().fieldName(i), importance[i]); } int[] prediction = Validation.test(model, USPS.test); int error = Error.of(USPS.testy, prediction); System.out.println("Error = " + error); assertEquals(897, model.size()); assertEquals(324, error); DecisionTree lean = model.prune(USPS.test); System.out.println(lean); importance = lean.importance(); for (int i = 0; i < importance.length; i++) { System.out.format("%-15s %.4f%n", lean.schema().fieldName(i), importance[i]); } prediction = Validation.test(model, USPS.test); error = Error.of(USPS.testy, prediction); System.out.println("Error of old model after pruning = " + error); assertEquals(897, model.size()); assertEquals(324, error); prediction = Validation.test(lean, USPS.test); error = Error.of(USPS.testy, prediction); System.out.println("Error of pruned model after pruning = " + error); assertEquals(743, lean.size()); assertEquals(273, error); }
public DecisionTree prune(DataFrame test) { return prune(test, formula, labels); }
DecisionTree extends CART implements SoftClassifier<Tuple>, DataFrameClassifier { public DecisionTree prune(DataFrame test) { return prune(test, formula, labels); } }
DecisionTree extends CART implements SoftClassifier<Tuple>, DataFrameClassifier { public DecisionTree prune(DataFrame test) { return prune(test, formula, labels); } DecisionTree(DataFrame x, int[] y, StructField response, int k, SplitRule rule, int maxDepth, int maxNodes, int nodeSize, int mtry, int[] samples, int[][] order); private  DecisionTree(Formula formula, StructType schema, StructField response, Node root, int k, SplitRule rule, double[] importance, IntSet labels); }
DecisionTree extends CART implements SoftClassifier<Tuple>, DataFrameClassifier { public DecisionTree prune(DataFrame test) { return prune(test, formula, labels); } DecisionTree(DataFrame x, int[] y, StructField response, int k, SplitRule rule, int maxDepth, int maxNodes, int nodeSize, int mtry, int[] samples, int[][] order); private  DecisionTree(Formula formula, StructType schema, StructField response, Node root, int k, SplitRule rule, double[] importance, IntSet labels); static DecisionTree fit(Formula formula, DataFrame data); static DecisionTree fit(Formula formula, DataFrame data, Properties prop); static DecisionTree fit(Formula formula, DataFrame data, SplitRule rule, int maxDepth, int maxNodes, int nodeSize); @Override int predict(Tuple x); @Override int predict(Tuple x, double[] posteriori); @Override Formula formula(); @Override StructType schema(); DecisionTree prune(DataFrame test); }
DecisionTree extends CART implements SoftClassifier<Tuple>, DataFrameClassifier { public DecisionTree prune(DataFrame test) { return prune(test, formula, labels); } DecisionTree(DataFrame x, int[] y, StructField response, int k, SplitRule rule, int maxDepth, int maxNodes, int nodeSize, int mtry, int[] samples, int[][] order); private  DecisionTree(Formula formula, StructType schema, StructField response, Node root, int k, SplitRule rule, double[] importance, IntSet labels); static DecisionTree fit(Formula formula, DataFrame data); static DecisionTree fit(Formula formula, DataFrame data, Properties prop); static DecisionTree fit(Formula formula, DataFrame data, SplitRule rule, int maxDepth, int maxNodes, int nodeSize); @Override int predict(Tuple x); @Override int predict(Tuple x, double[] posteriori); @Override Formula formula(); @Override StructType schema(); DecisionTree prune(DataFrame test);  }