示例#1
0
 public void testInducedDecisionTreeClassifiesRestaurantDataSetCorrectly()
 {
     DecisionTreeLearner learner = new DecisionTreeLearner(
             createInducedRestaurantDecisionTree(), "Unable to clasify");
     int[] results = learner.test(DataSetFactory.getRestaurantDataSet());
     Assert.AreEqual(12, results[0]);
     Assert.AreEqual(0, results[1]);
 }
示例#2
0
        public void testDefaultUsedWhenTrainingDataSetHasNoExamples()
        {
            // tests RecursionBaseCase#1
            DataSet ds = DataSetFactory.getRestaurantDataSet();
            DecisionTreeLearner learner = new DecisionTreeLearner();

            DataSet ds2 = ds.emptyDataSet();
            Assert.AreEqual(0, ds2.size());

            learner.train(ds2);
            Assert.AreEqual("Unable To Classify", learner.predict(ds
                    .getExample(0)));
        }
示例#3
0
        public void testStumpPredictionForDataSet()
        {
            DataSet ds = DataSetFactory.getRestaurantDataSet();

            List<String> unmatchedValues = new List<String>();
            unmatchedValues.Add(NO);
            DecisionTree tree = DecisionTree.getStumpFor(ds, "hungry", YES, YES,
                    unmatchedValues, "Unable to Classify");
            DecisionTreeLearner learner = new DecisionTreeLearner(tree,
                    "Unable to Classify");
            int[] result = learner.test(ds);
            Assert.AreEqual(5, result[0]);
            Assert.AreEqual(7, result[1]);
        }
示例#4
0
        public void testClassificationReturnedWhenAllExamplesHaveTheSameClassification()
        {
            // tests RecursionBaseCase#2
            DataSet ds = DataSetFactory.getRestaurantDataSet();
            DecisionTreeLearner learner = new DecisionTreeLearner();

            DataSet ds2 = ds.emptyDataSet();

            // all 3 examples have the same classification (willWait = yes)
            ds2.add(ds.getExample(0));
            ds2.add(ds.getExample(2));
            ds2.add(ds.getExample(3));

            learner.train(ds2);
            Assert.AreEqual("Yes", learner.predict(ds.getExample(0)));
        }
示例#5
0
        public void testMajorityReturnedWhenAttributesToExamineIsEmpty()
        {
            // tests RecursionBaseCase#2
            DataSet ds = DataSetFactory.getRestaurantDataSet();
            DecisionTreeLearner learner = new DecisionTreeLearner();

            DataSet ds2 = ds.emptyDataSet();

            // 3 examples have classification = "yes" and one ,"no"
            ds2.add(ds.getExample(0));
            ds2.add(ds.getExample(1));// "no"
            ds2.add(ds.getExample(2));
            ds2.add(ds.getExample(3));
            ds2.setSpecification(new MockDataSetSpecification("will_wait"));

            learner.train(ds2);
            Assert.AreEqual("Yes", learner.predict(ds.getExample(1)));
        }
示例#6
0
 public void testInducedTreeClassifiesDataSetCorrectly()
 {
     DataSet ds = DataSetFactory.getRestaurantDataSet();
     DecisionTreeLearner learner = new DecisionTreeLearner();
     learner.train(ds);
     int[] result = learner.test(ds);
     Assert.AreEqual(12, result[0]);
     Assert.AreEqual(0, result[1]);
 }