コード例 #1
0
ファイル: DecissionTreeTests.cs プロジェクト: netmatze/NetML
        public void MushroomDecisionTreeTest()
        {
            DataSetLoader dataSetLoader = new DataSetLoader();

            Console.WriteLine(" Reading DataSet.. ");
            var mushroom = dataSetLoader.SelectMushroom();
            DecisionTreeClassifier decisionTreeClassifier =
                new DecisionTreeClassifier(mushroom, new ShannonEntropySplitter());

            decisionTreeClassifier.Train();
            var mushroomTest = dataSetLoader.SelectMushroom();
            var trueCounter  = 0;
            var counter      = 0;

            foreach (var item in mushroomTest)
            {
                var outputValue = decisionTreeClassifier.Classify(item.Item1);
                if (outputValue == item.Item2)
                {
                    trueCounter++;
                }
                Debug.WriteLine(string.Format("Value {0} - Predicted {1} = {2}",
                                              item.Item2, outputValue, (outputValue == item.Item2) ? "true" : "false"));
                counter++;
            }
            Debug.WriteLine(string.Format("Data {0} - True {1} Verhältnis: {2}",
                                          counter.ToString(), trueCounter.ToString(), (Convert.ToDouble(trueCounter) / Convert.ToDouble(counter)).ToString()));
        }
コード例 #2
0
        public void MushroomSupportVectorMachineClassifierTest()
        {
            DataSetLoader dataSetLoader = new DataSetLoader();

            Console.WriteLine(" Reading DataSet.. ");
            var mushroom = dataSetLoader.SelectMushroom();

            for (double i = 0; i < 1; i = i + 1)
            {
                Kernel        kernel = new LinearKernel();
                SVMClassifier mushroomSVMClassifier = new SVMClassifier(mushroom, kernel, 0.001, 10.0);
                mushroomSVMClassifier.Train();
                var mushroomTest = dataSetLoader.SelectMushroom();
                var trueCounter  = 0;
                var counter      = 0;
                foreach (var item in mushroomTest)
                {
                    var outputValue = mushroomSVMClassifier.Classify(item.Item1);
                    if (outputValue == item.Item2)
                    {
                        trueCounter++;
                    }
                    Debug.WriteLine(string.Format("Value {0} - Predicted {1} = {2}",
                                                  item.Item2, outputValue, (outputValue == item.Item2) ? "true" : "false"));
                    counter++;
                }
                Debug.WriteLine(string.Format(" i = {0} Data {1} - True {2} Verhältnis: {3}", i,
                                              counter.ToString(), trueCounter.ToString(), (Convert.ToDouble(trueCounter) / Convert.ToDouble(counter)).ToString()));
            }
        }
コード例 #3
0
        public void NaiveBayesMushroomTest()
        {
            DataSetLoader dataSetLoader = new DataSetLoader();

            Console.WriteLine(" Reading DataSet.. ");
            var mushroom = dataSetLoader.SelectMushroom();

            for (double i = 0; i < 1; i = i + 1)
            {
                NaiveBayesClassifier naiveBayes =
                    new NaiveBayesClassifier(mushroom, new LinearBayesKernel(mushroom));
                var mushroomTests = dataSetLoader.SelectMushroom();
                var trueCounter   = 0;
                var counter       = 0;
                foreach (var item in mushroomTests)
                {
                    var outputValue = naiveBayes.Classify(item.Item1);
                    if (outputValue == item.Item2)
                    {
                        trueCounter++;
                    }
                    Debug.WriteLine(string.Format("Value {0} - Predicted {1} = {2}",
                                                  item.Item2, outputValue, (outputValue == item.Item2) ? "true" : "false"));
                    counter++;
                }
                Debug.WriteLine(string.Format(" i = {0} Data {1} - True {2} Verhältnis: {3}", i,
                                              counter.ToString(), trueCounter.ToString(), (Convert.ToDouble(trueCounter) / Convert.ToDouble(counter)).ToString()));
            }
        }
コード例 #4
0
        public void MushroomsNeuronalNetworkClassifierTest()
        {
            DataSetLoader dataSetLoader = new DataSetLoader();

            Console.WriteLine(" Reading DataSet.. ");
            var mushroom = dataSetLoader.SelectNeuronalNetworksMushroom();

            for (double i = 0; i < 1; i = i + 1)
            {
                NeuronalNetworkClassifier neuronalNetworkClassifier =
                    new NeuronalNetworkClassifier(mushroom, 21, 2, 21, 50, 0.2);
                neuronalNetworkClassifier.Train();
                var mushroomTest = dataSetLoader.SelectMushroom();
                var trueCounter  = 0;
                var counter      = 0;
                foreach (var item in mushroomTest)
                {
                    var    outputValue  = neuronalNetworkClassifier.ClassifiyMultibleResultValue(item.Item1);
                    var    resultString = String.Empty;
                    double maxValue     = 0.0;
                    int    innerCounter = 0;
                    int    maxItem      = 0;
                    foreach (var value in outputValue)
                    {
                        if (value > maxValue)
                        {
                            maxValue = value;
                            maxItem  = innerCounter;
                        }
                        innerCounter++;
                    }
                    if (maxItem == item.Item2)
                    {
                        trueCounter++;
                    }
                    Debug.WriteLine(string.Format("Value {0} - Predicted {1} = {2}",
                                                  item.Item2, maxItem, (maxItem == item.Item2) ? "true" : "false"));
                    counter++;
                }
                Debug.WriteLine(string.Format(" i = {0} Data {1} - True {2} Verhältnis: {3}", i,
                                              counter.ToString(), trueCounter.ToString(), (Convert.ToDouble(trueCounter) / Convert.ToDouble(counter)).ToString()));
            }
        }