train() public method

public train ( DataSet ds ) : void
ds AIMA.Core.Learning.Framework.DataSet
return void
Example #1
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)));
        }
Example #2
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)));
        }
Example #3
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)));
        }
Example #4
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]);
 }