Java Reference
In-Depth Information
public class
TestClassifier
extends
TestCase {
private
DecisionTree buildTree(){
Node root
#
new
Node("AC");
Node n1
#
new
Node("ABS");
Node n2
#
new
Node("ABS");
root.addChild("yes",n1);
root.addChild("no",n2);
Node l1
#
new
Node("high");
Node l2
#
new
Node("medium");
Node l3
#
new
Node("medium");
Node l4
#
new
Node("low");
n1.addChild("yes",l1);
n1.addChild("no",l2);
n2.addChild("yes",l3);
n2.addChild("no",l4);
return new
DecisionTree(root);
}
public
void testCategory(){
DecisionTree dt
#
buildTree();
FeatureType yn
#
new
FeatureType("YesNo",
new
String[]{"yes","no"});
Feature[] features
#
new
Feature[] {
new
Feature("AC","yes",yn),
new
Feature("ABS","yes",yn) };
Item item
#
new
Item("car",features);
String category
#
dt.assignCategory(item);
assertEquals("high",category);
item.setValue("AC","no");
category
#
dt.assignCategory(item);
assertEquals("medium",category);
item.setValue("AC","yes");
item.setValue("ABS","no");
category
#
dt.assignCategory(item);
assertEquals("medium",category);
item.setValue("AC","no");
category
#
dt.assignCategory(item);
assertEquals("low",category);
}
}
4.5
■
Prototype 2: Criteria representation
The prototype developed in this iteration provides a textual representation
of the decision tree. The representation has the goal of being easy to under-
stand, so it can be used as feedback to the problem expert.