Skip to content

aurora: Decision Tree

Clouke edited this page May 5, 2023 · 2 revisions

Build your Decision Tree

The Decision Tree is built by passing a list of maps as the training data, with each map representing a single instance in the dataset. The target attribute is also specified.

DecisionTree<String> tree = new DecisionTree<>(data, targetAttribute);

Or build an empty DecisionTree:

DecisionTree<String> tree = new DecisionTree<>();

Train your Decision Tree

tree.train(data, targetAttribute);

Predict

String prediction = tree.predict(instance);

Example of using a Decision Tree in NLP

List<Map<String, String>> instance = new ArrayList<>();
Map<String, String> data = new HashMap<>();
for (MessageNode node : nodes) {
  if (nodes.size() == i + 1) break; // no next node

  MessageNode nextNode = nodes.get(i + 1);
  String word = node.content;
  String reply = nextNode.content;

  data.put(word, reply);
  i++;
}
instance.add(data);
tree.train(instance, "your_target_here");