Ejemplo n.º 1
0
        public void testDecisionListMerge()
        {
            DecisionList dlist1 = new DecisionList("Yes", "No");
            DecisionList dlist2 = new DecisionList("Yes", "No");
            DataSet      ds     = DataSetFactory.getRestaurantDataSet();

            aima.net.learning.inductive.DecisionListTest test1 = new aima.net.learning.inductive.DecisionListTest();
            test1.add("type", "Thai"); // doesn't match first example
            dlist1.add(test1, "test1success");

            aima.net.learning.inductive.DecisionListTest test2 = new aima.net.learning.inductive.DecisionListTest();
            test2.add("type", "French");
            dlist2.add(test2, "test2success");// matches first example

            DecisionList dlist3 = dlist1.mergeWith(dlist2);

            Assert.AreEqual("test2success", dlist3.predict(ds.getExample(0)));
        }
Ejemplo n.º 2
0
        private DecisionList decisionListLearning(DataSet ds)
        {
            if (ds.size() == 0)
            {
                return(new DecisionList(positive, negative));
            }
            ICollection <DecisionListTest> possibleTests = testFactory.createDLTestsWithAttributeCount(ds, 1);
            DecisionListTest test = getValidTest(possibleTests, ds);

            if (test == null)
            {
                return(new DecisionList(null, FAILURE));
            }
            // at this point there is a test that classifies some subset of examples
            // with the same target value
            DataSet      matched = test.matchedExamples(ds);
            DecisionList list    = new DecisionList(positive, negative);

            list.add(test, matched.getExample(0).targetValue());
            return(list.mergeWith(decisionListLearning(test.unmatchedExamples(ds))));
        }