Beispiel #1
0
        public override void Train()
        {
            List <double[]>         FeaturSpace    = new List <double[]>();
            List <int>              FeaturLabel    = new List <int>();
            List <List <double[]> > DataWindows    = new List <List <double[]> >();
            List <List <int> >      LabelWindows   = new List <List <int> >();
            FeatureManager          featureManager = new FeatureManager();

            featureManager.Add(new Mean(1, 2, 3));
            featureManager.Add(new StandardDeviation(1, 2, 3));
            featureManager.Add(new MeanAbsoluteDeviation(1, 2, 3));
            featureManager.Add(new AverageTimeBetweenPeaks(0, 1, 2, 3));
            featureManager.Add(new ResultantAcceleration());
            featureManager.Add(new BinDistribution(10, 1, 2, 3));
            //featureManager.Add(new PreProcessData());

            var dataReader = new CSVReader <double[]>("data.txt", false, (dynamic output) =>
            {
                DataWindows = output;
                DataWindows.ForEach(window =>
                {
                    FeaturSpace.Add(featureManager.Generate(window).ToArray());
                });

                var labelReader = new CSVReader <int>("label.txt", false, (dynamic outputLabels) =>
                {
                    LabelWindows = outputLabels;
                    LabelWindows.ForEach(row =>
                    {
                        FeaturLabel.Add(row.GroupBy(x => x).OrderByDescending(g => g.Count()).Take(1).Select(i => i.Key).First());
                    });

                    DecisionTreeClassifier dt = new DecisionTreeClassifier(FusionFramework.Classifiers.DecisionTreeLearningAlgorithms.C45Learning);
                    dt.Train(FeaturSpace, FeaturLabel, true);
                    dt.Save("DecisionTreeWSDM");
                }, new SlidingWindow <int>(200, 0));
                labelReader.Start();
            }, new SlidingWindow <double[]>(200, 0));

            dataReader.Add(new Normalize());
            dataReader.Start();
        }