Java Reference
In-Depth Information
Table 4.2 Training set
Item
AC
ABS
Expected category
1
Yes
Yes
High
2
No
No
Low
3
Yes
No
Medium
4
No
Yes
Medium
create the items, by means of the createItem() method, and add them to
the training set mapping them to their categories;
create a decision tree classifier based on the training set; and
check if the classifier classifies correctly the test set element.
public class TestTraining extends TestCase {
public TestTraining(String arg0) {
super (arg0);
}
private Item createItem(String ac, String abs){
Feature[] features # new Feature[] {
new Feature("AC",ac,yn),
new Feature("ABS",abs,yn)
};
return new Item("car",features);
}
private FeatureType yn # new FeatureType("YesNo",
new String[]{"yes","no"});
public void testExample(){
Map items # new HashMap();
Map features # new HashMap();
features.put("AC",yn);
features.put("ABS",yn);
Item item1 # createItem("yes","yes");
items.put(item1,"high");
Item item2 # createItem("yes","no");
items.put(item2,"medium");
Item item3 # createItem("no","yes");
items.put(item3,"medium");
Item item4 # createItem("no","no");
items.put(item4,"low");
DecisionTree dc # new DecisionTree(items,features);
assertEquals("high",dc.assignCategory(item1));
assertEquals("medium",dc.assignCategory(item2));
assertEquals("medium",dc.assignCategory(item3));
assertEquals("low",dc.assignCategory(item4));
}
}
Search WWH ::




Custom Search