protected void cleanup(Context context) throws IOException, InterruptedException {
// prepare the data
log.debug("partition: {} numInstances: {}", partition, instances.size());
Data data = new Data(getDataset(), instances);
Bagging bagging = new Bagging(getTreeBuilder(), data);
TreeID key = new TreeID();
log.debug("Building {} trees", nbTrees);
for (int treeId = 0; treeId < nbTrees; treeId++) {
log.debug("Building tree number : {}", treeId);
Node tree = bagging.build(rng);
key.set(partition, firstTreeId + treeId);
if (isOutput()) {
MapredOutput emOut = new MapredOutput(tree);