示例#1
0
        public static void RunConventional()
        {
            AccuracyMeasure accuracyMeasure = new AccuracyMeasure();

            foreach (string dataset in GetDatasetFolds(DatasetNamesFile))
            {
                //----------------------------------------
                Console.WriteLine("Data Table:" + dataset);
                //----------------------------------------

                //try
                {
                    double quality1 = 0;
                    double quality2 = 0;
                    double quality3 = 0;

                    double quality4 = 0;
                    double quality5 = 0;
                    double quality6 = 0;

                    double quality7 = 0;
                    double quality8 = 0;
                    double quality9 = 0;


                    for (_currentFold = 0; _currentFold < _folds; _currentFold++)
                    {
                        //----------------------------------------
                        //Console.WriteLine("Fold:" + _currentFold.ToString());
                        //----------------------------------------

                        DataMining.Data.Dataset[] tables      = LoadTrainingAndTestingData(dataset, _currentFold);
                        DataMining.Data.Dataset   trainingSet = tables[0];
                        DataMining.Data.Dataset   testingSet  = tables[1];



                        KNearestNeighbours knn1 = SingleTest.CreateKNNClassifier(1, trainingSet, false);
                        quality1 += SingleTest.TestClassifier(knn1, testingSet, accuracyMeasure);
                        //------------------------------------------------------------------

                        KNearestNeighbours knn11 = SingleTest.CreateKNNClassifier(11, trainingSet, false);
                        quality2 += SingleTest.TestClassifier(knn11, testingSet, accuracyMeasure);
                        //------------------------------------------------------------------

                        KNearestNeighbours knn21 = SingleTest.CreateKNNClassifier(21, trainingSet, false);
                        quality3 += SingleTest.TestClassifier(knn21, testingSet, accuracyMeasure);
                        //------------------------------------------------------------------

                        //------------------------------------------------------------------
                        //------------------------------------------------------------------

                        NearestClassClassifier ncc0 = SingleTest.CreateNCClassifier(trainingSet, 0);
                        quality4 += SingleTest.TestClassifier(ncc0, testingSet, accuracyMeasure);
                        //------------------------------------------------------------------

                        NearestClassClassifier ncc5 = SingleTest.CreateNCClassifier(trainingSet, 0.5);
                        quality5 += SingleTest.TestClassifier(ncc5, testingSet, accuracyMeasure);
                        //------------------------------------------------------------------

                        NearestClassClassifier ncc1 = SingleTest.CreateNCClassifier(trainingSet, 0.9);
                        quality6 += SingleTest.TestClassifier(ncc1, testingSet, accuracyMeasure);
                        ////------------------------------------------------------------------

                        ////------------------------------------------------------------------
                        ////------------------------------------------------------------------

                        GaussianKernelEstimator gcc0 = SingleTest.CreateGKClassifier(trainingSet, 0);
                        quality7 += SingleTest.TestClassifier(gcc0, testingSet, accuracyMeasure);
                        //------------------------------------------------------------------

                        GaussianKernelEstimator gcc5 = SingleTest.CreateGKClassifier(trainingSet, 0.25);
                        quality8 += SingleTest.TestClassifier(gcc5, testingSet, accuracyMeasure);
                        //------------------------------------------------------------------

                        GaussianKernelEstimator gcc1 = SingleTest.CreateGKClassifier(trainingSet, 0.5);
                        quality9 += SingleTest.TestClassifier(gcc1, testingSet, accuracyMeasure);
                    }

                    quality1 = Math.Round((quality1 / _folds) * 100, 2);
                    quality2 = Math.Round((quality2 / _folds) * 100, 2);
                    quality3 = Math.Round((quality3 / _folds) * 100, 2);

                    quality4 = Math.Round((quality4 / _folds) * 100, 2);
                    quality5 = Math.Round((quality5 / _folds) * 100, 2);
                    quality6 = Math.Round((quality6 / _folds) * 100, 2);

                    quality7 = Math.Round((quality7 / _folds) * 100, 2);
                    quality8 = Math.Round((quality8 / _folds) * 100, 2);
                    quality9 = Math.Round((quality9 / _folds) * 100, 2);

                    Console.WriteLine("1NN: " + dataset + " - Accuracy=" + quality1);
                    SaveResults(dataset, "1NN", quality1.ToString());

                    Console.WriteLine("11NN: " + dataset + " - Accuracy=" + quality2);
                    SaveResults(dataset, "11NN", quality2.ToString());

                    Console.WriteLine("21NN: " + dataset + " - Accuracy=" + quality3);
                    SaveResults(dataset, "21NN", quality3.ToString());


                    Console.WriteLine("NCC-0: " + dataset + " - Accuracy=" + quality4);
                    SaveResults(dataset, "NCC-0", quality4.ToString());

                    Console.WriteLine("NCC-0.5: " + dataset + " - Accuracy=" + quality5);
                    SaveResults(dataset, "NCC-0.5", quality5.ToString());

                    Console.WriteLine("NCC-1: " + dataset + " - Accuracy=" + quality6);
                    SaveResults(dataset, "NCC-1", quality6.ToString());


                    Console.WriteLine("GKE-0: " + dataset + " - Accuracy=" + quality7);
                    SaveResults(dataset, "GKE-0", quality7.ToString());

                    Console.WriteLine("GKE-0.25: " + dataset + " - Accuracy=" + quality8);
                    SaveResults(dataset, "GKE-0.25", quality8.ToString());

                    Console.WriteLine("GKE-0.5: " + dataset + " - Accuracy=" + quality9);
                    SaveResults(dataset, "GKE-0.5", quality9.ToString());

                    Console.WriteLine("-------------------------------------------");
                    Console.WriteLine("-------------------------------------------");
                    Console.WriteLine("-------------------------------------------");
                }
                //catch (Exception ex)
                {
                    //LogError(ex);
                    //  Console.WriteLine(ex.Message);
                }
            }
        }