return getPredictionForNClasses(attributes);
}
}
private PredictionMap getPredictionForNClasses(AttributesMap attributes) {
PredictionMap sumsByClassification = new PredictionMap(new HashMap<Serializable, Double>());
for (Tree tree : trees) {
final PredictionMap treeProbs = tree.predict(attributes);
for (Map.Entry<Serializable, Double> tpe : treeProbs.entrySet()) {
Double sum = sumsByClassification.get(tpe.getKey());
if (sum == null) sum = 0.0;
sum += tpe.getValue();
sumsByClassification.put(tpe.getKey(), sum);
}
}
PredictionMap probsByClassification = new PredictionMap(new HashMap<Serializable, Double>());
for (Map.Entry<Serializable, Double> sumEntry : sumsByClassification.entrySet()) {
probsByClassification.put(sumEntry.getKey(), sumEntry.getValue() / trees.size());
}
return probsByClassification;
}