public void RandomForestsCrossValidationTest_2()
        {
            this.ProcessPcapFile(SnoopersPcaps.Default.app_identification_dnsHttpTls_cap);

            var applicationProtocolModelEvaluator = this.AppIdentService.CreateApplicationProtocolModels(this.L7Conversations, 10);
            var featureVectors      = applicationProtocolModelEvaluator.TrainingFeatureVectors.ToList();
            var appIdentAcordSource = new AppIdentAcordSource();

            appIdentAcordSource.Init(featureVectors);

            Console.WriteLine($"Feature vectors: {featureVectors.Count}");
            var featureSelection = new FeatureSelection(appIdentAcordSource.FeatureSelector);

            featureSelection.ProcessFeatureSelection(appIdentAcordSource, 0.5);

            foreach (var feature in featureSelection.FeatureSelector.SelectedFeatures)
            {
                Console.WriteLine($"{feature.Name}");
            }

            var rfcModel = this.AccordAppIdent.GetBestRandomForestsWithGridSearch(appIdentAcordSource, out var bestParameters, out var minError);
            // get the cross validation results
            var cvResults = this.AccordAppIdent.GetCrossValidationResultsOfRandomForestModel(appIdentAcordSource, bestParameters);

            Console.WriteLine("### CV Results ###");
            Console.WriteLine("\n### Training stats ###");
            Console.WriteLine(">> model error mean: {0}\n>> model std:  {1}", Math.Round(cvResults.Training.Mean, 6), Math.Round(cvResults.Training.StandardDeviation, 6));
            Console.WriteLine("\n### Validation stats ###");
            Console.WriteLine(">> model error mean: {0}\n>> model std:  {1}", Math.Round(cvResults.Validation.Mean, 6), Math.Round(cvResults.Validation.StandardDeviation, 6));

            var minErorr   = cvResults.Validation.Values.Min();
            var bestIndex  = cvResults.Validation.Values.IndexOf(minErorr);
            var classifier = cvResults.Models[bestIndex];

            var validationDataSource = classifier.Tag as AccordAppIdent.ValidationDataSource;
            var predictedValues      = classifier.Model.Decide(validationDataSource.ValidationInputs);

            var i = 0;

            foreach (var label in appIdentAcordSource.Labels.Distinct())
            {
                var conf = new ConfusionMatrix(validationDataSource.ValidationOutputs, predictedValues, i++);
                Console.WriteLine($"##########################");
                Console.WriteLine($"Protocol: {label}");
                Console.WriteLine($"TP: {conf.TruePositives}");
                Console.WriteLine($"TN: {conf.TrueNegatives}");
                Console.WriteLine($"FN: {conf.FalseNegatives}");
                Console.WriteLine($"FP: {conf.FalsePositives}");
                Console.WriteLine($"Accuracy: {conf.Accuracy}");
                Console.WriteLine($"Precision: {conf.Precision}");
                Console.WriteLine($"Specificity: {conf.Specificity}");
                Console.WriteLine($"Sensitivity: {conf.Sensitivity}");
                Console.WriteLine($"FScore: {conf.FScore}");
            }
        }
        public FeatureSelector EliminateCorelatedFeatures(AppIdentAcordSource appIdentAcordSource, double trashold, AppIdentTestContext appIdentTestContext)
        {
            var featureSelection = new FeatureSelection();

            featureSelection.ProcessFeatureSelection(appIdentAcordSource, trashold);

            var featureSelector = appIdentAcordSource.FeatureSelector;

            appIdentTestContext.Save(featureSelector);
            return(featureSelector);
        }
        //[DotMemoryUnit(CollectAllocations = true)]
        //[AssertTraffic(AllocatedSizeInBytes = 1024*1024)]
        public void CorrelationMatrixTest_M2()
        {
            MainWindow window = null;

            this.ProcessPcapFile(SnoopersPcaps.Default.app_identification_dnsHttpTls_cap);
            this.ProcessPcapFile(SnoopersPcaps.Default.app_identification_learn1_cap);
            this.ProcessPcapFile(SnoopersPcaps.Default.app_identification_refSkype_cap);
            this.ProcessPcapFile(SnoopersPcaps.Default.app_identification_streamSkypeHttpTls_cap);
            this.ProcessPcapFile(SnoopersPcaps.Default.app_identification_testM1_cap);
            this.ProcessPcapFile(SnoopersPcaps.Default.app_identification_testM2_cap);
            List <L7Conversation> testSet;
            var applicationProtocolModelEvaluator = this.AppIdentService.CreateApplicationProtocolModels(this.L7Conversations, 0.9, out testSet);
            var featureVectors      = applicationProtocolModelEvaluator.TrainingFeatureVectors.ToList();
            var appIdentAcordSource = new AppIdentAcordSource();

            appIdentAcordSource.Init(featureVectors);

            var featureSelection = new FeatureSelection(appIdentAcordSource.FeatureSelector);

            var selection         = featureSelection.ProcessFeatureSelection(appIdentAcordSource, 0.3);
            var correlationMatrix = selection.Last();


            // The dispatcher thread
            var t = new Thread(() =>
            {
                window = new MainWindow
                {
                    DataContext = new MainViewModel(appIdentAcordSource.FeatureNames, correlationMatrix)
                };
                //window.DataContext = new MainViewModel();
                // Initiates the dispatcher thread shutdown when the window closes
                window.Closed += (s, e) => window.Dispatcher.InvokeShutdown();
                window.Show();
                // Makes the thread support message pumping
                Dispatcher.Run();
            });

            // Configure the thread
            t.SetApartmentState(ApartmentState.STA);
            t.Start();
            t.Join();
        }