static void ensembleLearningDemo()
        {
            try
            {
                DataSet ds = DataSetFactory.getRestaurantDataSet();
                ICollection <DecisionTree> stumps   = DecisionTree.getStumpsFor(ds, "Yes", "No");
                ICollection <ILearner>     learners = CollectionFactory.CreateQueue <ILearner>();

                System.Console.WriteLine("\nStump Learners vote to decide in this algorithm");
                foreach (object stump in stumps)
                {
                    DecisionTree sl           = (DecisionTree)stump;
                    StumpLearner stumpLearner = new StumpLearner(sl, "No");
                    learners.Add(stumpLearner);
                }
                AdaBoostLearner learner = new AdaBoostLearner(learners, ds);
                learner.Train(ds);
                var   answer = learner.Predict(ds.getExample(0));
                int[] result = learner.Test(ds);
                System.Console.WriteLine("\nThis Ensemble Learner  classifies the data set with "
                                         + result[0]
                                         + " successes"
                                         + " and "
                                         + result[1]
                                         + " failures");
                System.Console.WriteLine("\n");
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Esempio n. 2
0
        public void testAdaBoostEnablesCollectionOfStumpsToClassifyDataSetAccurately()


        {
            DataSet ds = DataSetFactory.getRestaurantDataSet();
            ICollection <DecisionTree> stumps   = DecisionTree.getStumpsFor(ds, YES, "No");
            ICollection <ILearner>     learners = CollectionFactory.CreateQueue <ILearner>();

            foreach (object stump in stumps)
            {
                DecisionTree sl           = (DecisionTree)stump;
                StumpLearner stumpLearner = new StumpLearner(sl, "No");
                learners.Add(stumpLearner);
            }
            AdaBoostLearner learner = new AdaBoostLearner(learners, ds);

            learner.Train(ds);
            int[] result = learner.Test(ds);
            Assert.AreEqual(12, result[0]);
            Assert.AreEqual(0, result[1]);
        }