Example #1
0
        public static ResultObject EvaluateGreedyDR_WekaClassifier(string algorithm, string trainingSetPath, string testSetPath, Dataset trainingSet, bool useAttributes, bool useInstances)
        {
            Classifier classifier = WekaNETBridge.WekaClassification.GetWekaClassifier(algorithm, trainingSetPath);



            WekaNETBridge.WekaClassification wekaClassification = new WekaNETBridge.WekaClassification(trainingSetPath, classifier);

            WekaClassificationQualityEvaluator evaluator = new WekaClassificationQualityEvaluator(wekaClassification, true);

            DRLocalSearch localSearch = new DRLocalSearch(evaluator);

            Problem <DRComponent> problem = new Problem <DRComponent>(null, null, evaluator, localSearch);

            GreedyDR greedy = new GreedyDR(maxIterations, colonySize, convergenceIterations, problem, useAttributes, useInstances, trainingSet);

            greedy.OnPostAntSolutionContruction += OnPostAntSolutionContruction;
            greedy.OnPostColonyIteration        += OnPostColonyIteration;

            WekaNETBridge.WekaClassifier wekcaClassifier = greedy.CreateWekaClassifier();

            double quality           = WekaNETBridge.WekaClassification.EvaluateClassifier(wekcaClassifier, testSetPath);
            double attribueReduction = greedy.BestAnt.Solution.FeatureCount() / (double)trainingSet.Metadata.Attributes.Length;
            double instanceReduction = greedy.BestAnt.Solution.InstanceCount() / (double)trainingSet.Size;

            ResultObject result = new ResultObject()
            {
                Quality = quality, AttributeReduction = attribueReduction, InstanceReduciton = instanceReduction
            };

            return(result);
        }
Example #2
0
        public static Classifier GetWekaClassifier(string algorithm, string trainingSetPath)
        {
            Classifier classifier = null;

            switch (algorithm)
            {
            case "KNN":
            {
                classifier = new weka.classifiers.lazy.IB1();
                WekaNETBridge.WekaClassification wekaClassification = new WekaNETBridge.WekaClassification(trainingSetPath, classifier);
                classifier = wekaClassification.CreateClassifier();
            }
            break;

            case "NBayes":
            {
                classifier = new weka.classifiers.bayes.NaiveBayes();
                WekaNETBridge.WekaClassification wekaClassification = new WekaNETBridge.WekaClassification(trainingSetPath, classifier);
                classifier = wekaClassification.CreateClassifier();
            }
            break;

            case "JRip":
            {
                classifier = new weka.classifiers.rules.JRip();
                WekaNETBridge.WekaClassification wekaClassification = new WekaNETBridge.WekaClassification(trainingSetPath, classifier);
                classifier = wekaClassification.CreateClassifier();
            }
            break;

            case "J48":
            {
                classifier = new weka.classifiers.trees.J48();
                WekaNETBridge.WekaClassification wekaClassification = new WekaNETBridge.WekaClassification(trainingSetPath, classifier);
                classifier = wekaClassification.CreateClassifier();
            }
            break;

            case "NeuralNets":
            {
                classifier = new weka.classifiers.functions.MultilayerPerceptron();
                WekaNETBridge.WekaClassification wekaClassification = new WekaNETBridge.WekaClassification(trainingSetPath, classifier);
                classifier = wekaClassification.CreateClassifier();
            }
            break;

            case "SVM":
            {
                classifier = new weka.classifiers.functions.SMO();
                WekaNETBridge.WekaClassification wekaClassification = new WekaNETBridge.WekaClassification(trainingSetPath, classifier);
                classifier = wekaClassification.CreateClassifier();
            }
            break;
            }

            return(classifier);
        }
Example #3
0
        public static List <ResultObject> EvaluateACOMinerDR_WekaClassifier_Multi(string algorithm, string trainingSetPath, string testSetPath, Dataset trainingSet, bool useAttributes, bool useInstances)
        {
            Classifier classifier = WekaNETBridge.WekaClassification.GetWekaClassifier(algorithm, trainingSetPath);

            DefaultDRHeuristicCalculator calculator  = new DefaultDRHeuristicCalculator();
            DRComponentInvalidator       invalidator = new DRComponentInvalidator();


            WekaNETBridge.WekaClassification wekaClassification = new WekaNETBridge.WekaClassification(trainingSetPath, classifier);

            WekaClassificationQualityEvaluator evaluator = new WekaClassificationQualityEvaluator(wekaClassification, !useAttributes);

            DRLocalSearch localSearch = new DRLocalSearch(evaluator);

            Problem <DRComponent> problem = new Problem <DRComponent>(invalidator, calculator, evaluator, localSearch);

            ADRMiner acominer = new ADRMiner(maxIterations, colonySize, convergenceIterations, problem, useAttributes, useInstances, false, trainingSet);

            acominer.OnPostAntSolutionContruction += OnPostAntSolutionContruction;
            acominer.OnPostColonyIteration        += OnPostColonyIteration;

            acominer.Initialize();
            acominer.Work();


            List <ResultObject> results = new List <ResultObject>();

            foreach (string algo in WekaNETBridge.WekaClassification.GetWekaAlgorithmNames())
            {
                Classifier currentClassifier = WekaNETBridge.WekaClassification.GetWekaClassifier(algo, trainingSetPath);

                WekaNETBridge.WekaClassifier final = evaluator.CreateWekaClassifier(currentClassifier, acominer.BestAnt.Solution);

                double quality           = WekaNETBridge.WekaClassification.EvaluateClassifier(final, testSetPath);
                double attribueReduction = acominer.BestAnt.Solution.FeatureCount() / (double)trainingSet.Metadata.Attributes.Length;
                double instanceReduction = acominer.BestAnt.Solution.InstanceCount() / (double)trainingSet.Size;

                ResultObject result = new ResultObject()
                {
                    Quality = quality, AttributeReduction = attribueReduction, InstanceReduciton = instanceReduction
                };

                results.Add(result);
            }

            return(results);
        }
Example #4
0
        public static ResultObject EvaluateRandDR_WekaClassifier(string algorithm, string trainingSetPath, string testSetPath, Dataset trainingSet, bool useAttributes, bool useInstances)
        {
            Classifier classifier = WekaNETBridge.WekaClassification.GetWekaClassifier(algorithm, trainingSetPath);

            //DefaultDRHeuristicCalculator calculator = new DefaultDRHeuristicCalculator();

            DefaultHeuristicCalculator <DRComponent> calculator = new DefaultHeuristicCalculator <DRComponent>(trainingSet);
            DRComponentInvalidator invalidator = new DRComponentInvalidator();


            WekaNETBridge.WekaClassification wekaClassification = new WekaNETBridge.WekaClassification(trainingSetPath, classifier);

            WekaClassificationQualityEvaluator evaluator = new WekaClassificationQualityEvaluator(wekaClassification, true);

            DRLocalSearch localSearch = new DRLocalSearch(evaluator);

            Problem <DRComponent> problem = new Problem <DRComponent>(invalidator, calculator, evaluator, localSearch);

            RandomDR random = new RandomDR(maxIterations, colonySize, 50, problem, useAttributes, useInstances, false, trainingSet);

            random.OnPostAntSolutionContruction += OnPostAntSolutionContruction;
            random.OnPostColonyIteration        += OnPostColonyIteration;



            WekaNETBridge.WekaClassifier wekcaClassifier = random.CreateWekaClassifier();

            double quality           = WekaNETBridge.WekaClassification.EvaluateClassifier(wekcaClassifier, testSetPath);
            double attribueReduction = random.BestAnt.Solution.FeatureCount() / (double)trainingSet.Metadata.Attributes.Length;
            double instanceReduction = random.BestAnt.Solution.InstanceCount() / (double)trainingSet.Size;

            ResultObject result = new ResultObject()
            {
                Quality = quality, AttributeReduction = attribueReduction, InstanceReduciton = instanceReduction
            };

            return(result);
        }
Example #5
0
        public static ResultObject EvaluateACOMinerDR2_WekaClassifier(string algorithm, string trainingSetPath, string testSetPath, Dataset trainingSet, bool attributeFirst)
        {
            Classifier classifier = WekaNETBridge.WekaClassification.GetWekaClassifier(algorithm, trainingSetPath);

            ADRHeuristicCalculator calculator  = new ADRHeuristicCalculator();
            DRComponentInvalidator invalidator = new DRComponentInvalidator();


            WekaNETBridge.WekaClassification wekaClassification = new WekaNETBridge.WekaClassification(trainingSetPath, classifier);

            WekaClassificationQualityEvaluator evaluator = new WekaClassificationQualityEvaluator(wekaClassification, false);

            DRLocalSearch localSearch = new DRLocalSearch(evaluator);

            Problem <DRComponent> problem = new Problem <DRComponent>(invalidator, calculator, evaluator, localSearch);

            ADRMiner2 acominer = new ADRMiner2(maxIterations, colonySize, convergenceIterations, problem, attributeFirst, false, trainingSet);

            acominer.ACO1.OnPostAntSolutionContruction += OnPostAntSolutionContruction;
            acominer.ACO1.OnPostColonyIteration        += OnPostColonyIteration;
            acominer.ACO2.OnPostAntSolutionContruction += OnPostAntSolutionContruction;
            acominer.ACO2.OnPostColonyIteration        += OnPostColonyIteration;


            WekaNETBridge.WekaClassifier wekcaClassifier = acominer.CreateWekaClassifier();

            double quality = WekaNETBridge.WekaClassification.EvaluateClassifier(wekcaClassifier, testSetPath);

            double attribueReduction = acominer.BestSolution.AttributesToRemove().Length;
            double instanceReduction = acominer.BestSolution.InstanceCount() / (double)trainingSet.Size;

            ResultObject result = new ResultObject()
            {
                Quality = quality, AttributeReduction = attribueReduction, InstanceReduciton = instanceReduction
            };

            return(result);
        }
        //public DataMining.Data.Dataset LearningSet
        //{
        //    get { return this._learningSet; }
        //    set { this._learningSet = value; }
        //}

        //public DataMining.Data.Dataset ValidationSet
        //{
        //    get { return this._validationSet; }
        //    set { this._validationSet = value; }
        //}

        //public DataMining.ClassificationMeasures.IClassificationMeasure Measure
        //{
        //    get { return this._measure; }
        //}

        #endregion

        #region Constructor

        public WekaClassificationQualityEvaluator(WekaNETBridge.WekaClassification wekaClasification, bool skipAttributesValidation)
        {
            this._skipAttibutesValidation = skipAttributesValidation;
            this.WekaClassification       = wekaClasification;
        }