Data implements Cloneable { public Data subset(Condition condition) { List<Instance> subset = new ArrayList<Instance>(); for (Instance instance : instances) { if (condition.isTrueFor(instance)) { subset.add(instance); } } return new Data(dataset, subset); } Data(Dataset dataset, List<Instance> instances); int size(); boolean isEmpty(); boolean contains(Instance v); int indexof(Instance v); Instance get(int index); Data subset(Condition condition); Data rsubset(Random rng, double ratio); Data bagging(Random rng); Data bagging(Random rng, boolean[] sampled); Data rsplit(Random rng, int subsize); boolean isIdentical(); boolean identicalLabel(); double[] values(int attr); @Override Data clone(); @Override boolean equals(Object obj); @Override int hashCode(); int[] extractLabels(); static int[] extractLabels(Dataset dataset, FileSystem fs, Path path); int majorityLabel(Random rng); void countLabels(int[] counts); Dataset getDataset();  }
@Test public void testSubset() { int n = 10; for (int nloop = 0; nloop < n; nloop++) { int attr = rng.nextInt(data.getDataset().nbAttributes()); double[] values = data.values(attr); double value = values[rng.nextInt(values.length)]; Data eSubset = data.subset(Condition.equals(attr, value)); Data lSubset = data.subset(Condition.lesser(attr, value)); Data gSubset = data.subset(Condition.greaterOrEquals(attr, value)); for (int index = 0; index < DATA_SIZE; index++) { Instance instance = data.get(index); if (instance.get(attr) < value) { assertTrue(lSubset.contains(instance)); assertFalse(eSubset.contains(instance)); assertFalse(gSubset.contains(instance)); } else if (instance.get(attr) == value) { assertFalse(lSubset.contains(instance)); assertTrue(eSubset.contains(instance)); assertTrue(gSubset.contains(instance)); } else { assertFalse(lSubset.contains(instance)); assertFalse(eSubset.contains(instance)); assertTrue(gSubset.contains(instance)); } } } }