@Test public void testRegression() throws DescriptorException { Data[] datas = generateTrainingDataB(); DecisionForest[] forests = new DecisionForest[datas.length]; for (int i = 0; i < datas.length; i++) { Data[] subDatas = new Data[datas.length - 1]; int k = 0; for (int j = 0; j < datas.length; j++) { if (j != i) { subDatas[k] = datas[j]; k++; } } forests[i] = buildForest(subDatas); } double[][] predictions = new double[datas[0].size()][]; forests[0].classify(datas[0], predictions); assertArrayEquals(new double[]{20.0, 20.0}, predictions[0], EPSILON); assertArrayEquals(new double[]{39.0, 29.0}, predictions[1], EPSILON); assertArrayEquals(new double[]{Double.NaN, 29.0}, predictions[2], EPSILON); assertArrayEquals(new double[]{Double.NaN, 23.0}, predictions[17], EPSILON); predictions = new double[datas[1].size()][]; forests[1].classify(datas[1], predictions); assertArrayEquals(new double[]{30.0, 29.0}, predictions[19], EPSILON); predictions = new double[datas[2].size()][]; forests[2].classify(datas[2], predictions); assertArrayEquals(new double[]{29.0, 28.0}, predictions[9], EPSILON); assertEquals(20.0, forests[0].classify(datas[0].getDataset(), rng, datas[0].get(0)), EPSILON); assertEquals(34.0, forests[0].classify(datas[0].getDataset(), rng, datas[0].get(1)), EPSILON); assertEquals(29.0, forests[0].classify(datas[0].getDataset(), rng, datas[0].get(2)), EPSILON); }
public void classify(Data data, double[][] predictions) { Preconditions.checkArgument(data.size() == predictions.length, "predictions.length must be equal to data.size()"); if (data.isEmpty()) { return; } int treeId = 0; for (Node tree : trees) { for (int index = 0; index < data.size(); index++) { if (predictions[index] == null) { predictions[index] = new double[trees.size()]; } predictions[index][treeId] = tree.classify(data.get(index)); } treeId++; } }
DecisionForest implements Writable { public void classify(Data data, double[][] predictions) { Preconditions.checkArgument(data.size() == predictions.length, "predictions.length must be equal to data.size()"); if (data.isEmpty()) { return; } int treeId = 0; for (Node tree : trees) { for (int index = 0; index < data.size(); index++) { if (predictions[index] == null) { predictions[index] = new double[trees.size()]; } predictions[index][treeId] = tree.classify(data.get(index)); } treeId++; } } }
DecisionForest implements Writable { public void classify(Data data, double[][] predictions) { Preconditions.checkArgument(data.size() == predictions.length, "predictions.length must be equal to data.size()"); if (data.isEmpty()) { return; } int treeId = 0; for (Node tree : trees) { for (int index = 0; index < data.size(); index++) { if (predictions[index] == null) { predictions[index] = new double[trees.size()]; } predictions[index][treeId] = tree.classify(data.get(index)); } treeId++; } } private  DecisionForest();  DecisionForest(List<Node> trees); }
DecisionForest implements Writable { public void classify(Data data, double[][] predictions) { Preconditions.checkArgument(data.size() == predictions.length, "predictions.length must be equal to data.size()"); if (data.isEmpty()) { return; } int treeId = 0; for (Node tree : trees) { for (int index = 0; index < data.size(); index++) { if (predictions[index] == null) { predictions[index] = new double[trees.size()]; } predictions[index][treeId] = tree.classify(data.get(index)); } treeId++; } } private  DecisionForest();  DecisionForest(List<Node> trees); void classify(Data data, double[][] predictions); double classify(Dataset dataset, Random rng, Instance instance); long meanNbNodes(); long nbNodes(); long meanMaxDepth(); @Override boolean equals(Object obj); @Override int hashCode(); @Override void write(DataOutput dataOutput); @Override void readFields(DataInput dataInput); static DecisionForest read(DataInput dataInput); static DecisionForest load(Configuration conf, Path forestPath); }
DecisionForest implements Writable { public void classify(Data data, double[][] predictions) { Preconditions.checkArgument(data.size() == predictions.length, "predictions.length must be equal to data.size()"); if (data.isEmpty()) { return; } int treeId = 0; for (Node tree : trees) { for (int index = 0; index < data.size(); index++) { if (predictions[index] == null) { predictions[index] = new double[trees.size()]; } predictions[index][treeId] = tree.classify(data.get(index)); } treeId++; } } private  DecisionForest();  DecisionForest(List<Node> trees); void classify(Data data, double[][] predictions); double classify(Dataset dataset, Random rng, Instance instance); long meanNbNodes(); long nbNodes(); long meanMaxDepth(); @Override boolean equals(Object obj); @Override int hashCode(); @Override void write(DataOutput dataOutput); @Override void readFields(DataInput dataInput); static DecisionForest read(DataInput dataInput); static DecisionForest load(Configuration conf, Path forestPath);  }