public static void Test1() { AccuracyMeasure accuracyMeasure = new AccuracyMeasure(); IEnsembleClassificationStrategy majorityVote = new MajorityVoteStrategy(); IEnsembleClassificationStrategy weightedVote = new WeightedVoteStrategy(); DataMining.Data.Dataset[] tables = BatchTest2.LoadTrainingAndTestingData("audiology", 0); DataMining.Data.Dataset trainingSet = tables[0]; DataMining.Data.Dataset testingSet = tables[1]; //EnsembleClassifier ensemble = SingleTest.CreateGKAntIBMinerClassifier_ClassBaseWeights_Ensemble(trainingSet); EnsembleClassifier ensemble = SingleTest.CreateNCCAntIBMinerClassifier_ClassBasedWeights_Ensemble(trainingSet); //EnsembleClassifier ensemble = SingleTest.CreateKNNAntIBMinerClassifier_ClassBasedWeights_Ensemble(trainingSet,false); double quality1 = 0; double quality2 = 0; double quality3 = 0; quality1 += SingleTest.TestClassifier(ensemble[0], testingSet, accuracyMeasure); ensemble.Stratgy = majorityVote; quality2 += SingleTest.TestClassifier(ensemble, testingSet, accuracyMeasure); ensemble.Stratgy = weightedVote; quality3 += SingleTest.TestClassifier(ensemble, testingSet, accuracyMeasure); quality1 = Math.Round((quality1 / 1) * 100, 2); quality2 = Math.Round((quality2 / 1) * 100, 2); quality3 = Math.Round((quality3 / 1) * 100, 2); //------------------------------------------------------------------ Console.WriteLine("ACO-GKC-CB-CB: Accuracy=" + quality1); Console.WriteLine("ACO-GKC-CB-ens-MV: Accuracy=" + quality2); Console.WriteLine("ACO-GKC-CB-ens-WV: Accuracy=" + quality3); //Console.WriteLine(((KNearestNeighbours)ensemble[0]).KNeighbours.ToString()); Console.WriteLine("-------------------------------------------"); Console.WriteLine("-------------------------------------------"); Console.WriteLine("-------------------------------------------"); }
public static void RunACOIBL() { AccuracyMeasure accuracyMeasure = new AccuracyMeasure(); IEnsembleClassificationStrategy majorityVote = new MajorityVoteStrategy(); IEnsembleClassificationStrategy weightedVote = new WeightedVoteStrategy(); foreach (string dataset in GetDatasetFolds(DatasetNamesFile)) { //---------------------------------------- Console.WriteLine("Data Table:" + dataset); //---------------------------------------- #region ACO-KNN-CB try { double quality1 = 0; //double quality2 = 0; double quality3 = 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]; EnsembleClassifier ensemble = SingleTest.CreateKNNAntIBMinerClassifier_Ensemble(trainingSet, false); double trQuality = SingleTest.TestClassifier(ensemble[0], trainingSet, accuracyMeasure); double tsQuality = SingleTest.TestClassifier(ensemble[0], testingSet, accuracyMeasure); Console.WriteLine(trQuality); Console.WriteLine(tsQuality); quality1 += SingleTest.TestClassifier(ensemble[0], testingSet, accuracyMeasure); //ensemble.Stratgy = majorityVote; //quality2 += SingleTest.TestClassifier(ensemble, testingSet, accuracyMeasure); ensemble.Stratgy = weightedVote; quality3 += SingleTest.TestClassifier(ensemble, testingSet, accuracyMeasure); } quality1 = Math.Round((quality1 / _folds) * 100, 2); //quality2 = Math.Round((quality2 / _folds) * 100, 2); quality3 = Math.Round((quality3 / _folds) * 100, 2); //------------------------------------------------------------------ Console.WriteLine("ACO-KNN-CB: " + dataset + " - Accuracy=" + quality1); SaveResults(dataset, "ACO-KNN-CB", quality1.ToString()); // Console.WriteLine("ACO-KNN-CB-ens-MV: " + dataset + " - Accuracy=" + quality2); // SaveResults(dataset, "ACO-KNN-CB-ens-MV", quality2.ToString()); Console.WriteLine("ACO-KNN-CB-ens-WV: " + dataset + " - Accuracy=" + quality3); SaveResults(dataset, "ACO-KNN-CB-ens-WV", quality3.ToString()); Console.WriteLine("-------------------------------------------"); Console.WriteLine("-------------------------------------------"); Console.WriteLine("-------------------------------------------"); } catch (Exception ex) { LogError(ex); // Console.WriteLine(ex.Message); } #endregion return; #region ACO-KNN-CB-WV //try //{ // double quality1 = 0; // double quality2 = 0; // double quality3 = 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]; // EnsembleClassifier ensemble = SingleTest.CreateKNNAntIBMinerClassifier_ClassBasedWeights_Ensemble(trainingSet, true); // quality1 += SingleTest.TestClassifier(ensemble[0], testingSet, accuracyMeasure); // ensemble.Stratgy = majorityVote; // quality2 += SingleTest.TestClassifier(ensemble, testingSet, accuracyMeasure); // ensemble.Stratgy = weightedVote; // quality3 += SingleTest.TestClassifier(ensemble, testingSet, accuracyMeasure); // } // quality1 = Math.Round((quality1 / _folds) * 100, 2); // quality2 = Math.Round((quality2 / _folds) * 100, 2); // quality3 = Math.Round((quality3 / _folds) * 100, 2); // //------------------------------------------------------------------ // Console.WriteLine("ACO-KNN-CB-WV: " + dataset + " - Accuracy=" + quality1); // SaveResults(dataset, "ACO-KNN-CB-WV", k.ToString(), quality1.ToString()); // Console.WriteLine("ACO-KNN-CB-WV-ens-MV: " + dataset + " - Accuracy=" + quality2); // SaveResults(dataset, "ACO-KNN-CB-WV-ens-MV", k.ToString(), quality2.ToString()); // Console.WriteLine("ACO-KNN-CB-WV-ens-WV: " + dataset + " - Accuracy=" + quality3); // SaveResults(dataset, "ACO-KNN-CB-WV-ens-WV", k.ToString(), quality3.ToString()); // Console.WriteLine("-------------------------------------------"); // Console.WriteLine("-------------------------------------------"); // Console.WriteLine("-------------------------------------------"); //} //catch (Exception ex) //{ // LogError(ex); // // Console.WriteLine(ex.Message); //} #endregion #region ACO-NCC-CB try { double quality1 = 0; //double quality2 = 0; double quality3 = 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]; EnsembleClassifier ensemble = SingleTest.CreateNCCAntIBMinerClassifier_ClassBasedWeights_Ensemble(trainingSet); quality1 += SingleTest.TestClassifier(ensemble[0], testingSet, accuracyMeasure); //ensemble.Stratgy = majorityVote; //quality2 += SingleTest.TestClassifier(ensemble, testingSet, accuracyMeasure); ensemble.Stratgy = weightedVote; quality3 += SingleTest.TestClassifier(ensemble, testingSet, accuracyMeasure); } quality1 = Math.Round((quality1 / _folds) * 100, 2); //quality2 = Math.Round((quality2 / _folds) * 100, 2); quality3 = Math.Round((quality3 / _folds) * 100, 2); //------------------------------------------------------------------ Console.WriteLine("ACO-NCC-CB: " + dataset + " - Accuracy=" + quality1); SaveResults(dataset, "ACO-NNC-CB", quality1.ToString()); //Console.WriteLine("ACO-NNC-CB-ens-MV: " + dataset + " - Accuracy=" + quality2); //SaveResults(dataset, "ACO-NNC-CB-ens-MV", quality2.ToString()); Console.WriteLine("ACO-NNC-CB-ens-WV: " + dataset + " - Accuracy=" + quality3); SaveResults(dataset, "ACO-NNC-CB-ens-WV", quality3.ToString()); Console.WriteLine("-------------------------------------------"); Console.WriteLine("-------------------------------------------"); Console.WriteLine("-------------------------------------------"); } catch (Exception ex) { LogError(ex); // Console.WriteLine(ex.Message); } #endregion #region ACO-GKC-CB try { double quality1 = 0; //double quality2 = 0; double quality3 = 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]; EnsembleClassifier ensemble = SingleTest.CreateGKAntIBMinerClassifier_ClassBaseWeights_Ensemble(trainingSet); quality1 += SingleTest.TestClassifier(ensemble[0], testingSet, accuracyMeasure); //ensemble.Stratgy = majorityVote; //quality2 += SingleTest.TestClassifier(ensemble, testingSet, accuracyMeasure); ensemble.Stratgy = weightedVote; quality3 += SingleTest.TestClassifier(ensemble, testingSet, accuracyMeasure); } quality1 = Math.Round((quality1 / _folds) * 100, 2); //quality2 = Math.Round((quality2 / _folds) * 100, 2); quality3 = Math.Round((quality3 / _folds) * 100, 2); //------------------------------------------------------------------ Console.WriteLine("ACO-GKC-CB-CB: " + dataset + " - Accuracy=" + quality1); SaveResults(dataset, "ACO-GKC-CB", quality1.ToString()); //Console.WriteLine("ACO-GKC-CB-ens-MV: " + dataset + " - Accuracy=" + quality2); //SaveResults(dataset, "ACO-GKC-CB-ens-MV", quality2.ToString()); Console.WriteLine("ACO-GKC-CB-ens-WV: " + dataset + " - Accuracy=" + quality3); SaveResults(dataset, "ACO-GKC-CB-ens-WV", quality3.ToString()); Console.WriteLine("-------------------------------------------"); Console.WriteLine("-------------------------------------------"); Console.WriteLine("-------------------------------------------"); } catch (Exception ex) { LogError(ex); // Console.WriteLine(ex.Message); } #endregion } }