super.tearDown();
}
public void testBuildAndClassifyJ48() throws Exception
{
Classifier classifier = new J48();
FastVector attributes = new FastVector();
FastVector values = new FastVector();
values.addElement("sunny");
values.addElement("overcast");
values.addElement("rain");
attributes.addElement(new Attribute("outlook", values));
values = new FastVector();
values.addElement("false");
values.addElement("true");
attributes.addElement(new Attribute("windy", values));
attributes.addElement(new Attribute("humidity"));
attributes.addElement(new Attribute("temperature"));
values = new FastVector();
values.addElement("yes");
values.addElement("no");
attributes.addElement(new Attribute("play", values));
Instances dataset = new Instances("", attributes, 15);
dataset.add(createInstance(dataset, "sunny", "false", 85, 85, "no"));
dataset.add(createInstance(dataset, "sunny", "true", 80, 90, "no"));
dataset.add(createInstance(dataset, "overcast", "false", 83, 78, "yes"));
dataset.add(createInstance(dataset, "rain", "false", 70, 96, "yes"));
dataset.add(createInstance(dataset, "rain", "false", 68, 80, "yes"));
dataset.add(createInstance(dataset, "rain", "true", 65, 70, "no"));
dataset.add(createInstance(dataset, "overcast", "true", 64, 65, "yes"));
dataset.add(createInstance(dataset, "sunny", "false", 72, 95, "no"));
dataset.add(createInstance(dataset, "sunny", "false", 69, 70, "yes"));
dataset.add(createInstance(dataset, "rain", "false", 75, 80, "yes"));
dataset.add(createInstance(dataset, "sunny", "true", 75, 70, "yes"));
dataset.add(createInstance(dataset, "overcast", "true", 72, 90, "yes"));
dataset.add(createInstance(dataset, "overcast", "false", 81, 75, "yes"));
dataset.add(createInstance(dataset, "rain", "true", 71, 91, "no"));
dataset.setClassIndex(4);
classifier.buildClassifier(dataset);
System.out.println(classifier);
double result = classifier.classifyInstance(createInstance(dataset, "sunny", "false", 85, 85, Null.getValue()));
assertEquals(1.0, result, .1);
result = classifier.classifyInstance(createInstance(dataset, "sunny", "true", 80, 90, Null.getValue()));
assertEquals(1.0, result, .1);
result = classifier.classifyInstance(createInstance(dataset, "overcast", "false", 83, 78, "yes"));
assertEquals(0.0, result, .1);
result = classifier.classifyInstance(createInstance(dataset, "rain", "false", 70, 96, "yes"));
assertEquals(0.0, result, .1);
result = classifier.classifyInstance(createInstance(dataset, "rain", "false", 68, 80, "yes"));
assertEquals(0.0, result, .1);
}