예제 #1
0
        public override void Train(List <Tuple <double[], double> > data,
                                   DecisionTree.Splitter splitter)
        {
            List <Tuple <double, double[], double> > list = Initialize(data);
            var sample = data;
            var alpha  = 0.0;
            var epselonWrongCounter = 0.0;
            var epselon             = 0.0;
            var n = data.Count;

            for (int i = 0; i < ensembleSizeT; i++)
            {
                if (i > 0)
                {
                    sample = BuildSample(list);
                }
                var classifier = new
                                 DecisionTree.DecisionTreeClassifier(sample, splitter);
                classifier.Train();
                foreach (var value in sample)
                {
                    var result = classifier.Classify(value.Item1);
                    if (result != value.Item2)
                    {
                        epselonWrongCounter++;
                    }
                }
                epselon = epselonWrongCounter / (double)n;
                if (epselon == 0)
                {
                    classifiers.Add(new Tuple <double, DecisionTree.DecisionTreeClassifier>(alpha, classifier));
                    break;
                }
                else
                {
                    alpha = 0.5 * Math.Log(((1.0 - epselon) / epselon));
                    classifiers.Add(new Tuple <double, DecisionTree.DecisionTreeClassifier>(alpha, classifier));
                }
                list = Adjust(classifier, list, epselon);
                epselonWrongCounter = 0.0;
            }
        }
예제 #2
0
        public override void Train(List <Tuple <double[], double> > data,
                                   DecisionTree.Splitter splitter)
        {
            var n = data.Count;
            var bootstrapSampleSize = n * 0.8;
            var dataArray           = data.ToArray();

            for (int t = 0; t < ensembleSizeT; t++)
            {
                var    sample = new List <Tuple <double[], double> >();
                Random random = new Random();
                for (int i = 0; i < bootstrapSampleSize; i++)
                {
                    var number = random.Next(0, n);
                    sample.Add(dataArray[number]);
                }
                var classifier = new
                                 DecisionTree.DecisionTreeClassifier(sample, splitter);
                classifier.Train();
                classifiers.Add(classifier);
            }
        }