Ejemplo n.º 1
0
        public void IrisSupportVectorMachineClassifierTest()
        {
            DataSetLoader dataSetLoader = new DataSetLoader();

            Console.WriteLine(" Reading DataSet.. ");
            var irises = dataSetLoader.SelectIrises();

            for (double i = 0; i < 1; i = i + 1)
            {
                Kernel        kernel = new LinearKernel();
                SVMClassifier animalSVMClassifier = new SVMClassifier(irises, kernel, 0.001, 10.0);
                animalSVMClassifier.Train();
                var irisesTest  = dataSetLoader.SelectIrises();
                var trueCounter = 0;
                var counter     = 0;
                foreach (var item in irisesTest)
                {
                    var outputValue = animalSVMClassifier.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()));
            }
        }
Ejemplo n.º 2
0
        public void IrisDecisionTreeTest()
        {
            DataSetLoader dataSetLoader = new DataSetLoader();

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

            decisionTreeClassifier.Train();
            var animalsTest = dataSetLoader.SelectIrises();
            var trueCounter = 0;
            var counter     = 0;

            foreach (var item in animalsTest)
            {
                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()));
        }
Ejemplo n.º 3
0
        public void IrisBoostingTest()
        {
            DataSetLoader dataSetLoader = new DataSetLoader();

            Console.WriteLine(" Reading DataSet.. ");
            var irises = dataSetLoader.SelectIrises();

            for (double i = 0; i < 1; i = i + 1)
            {
                BoostingAlgorithmus boostingAlgorithmus =
                    new BoostingAlgorithmus(10);
                boostingAlgorithmus.Train(irises, new ShannonEntropySplitter());
                var irisesTest  = dataSetLoader.SelectIrises();
                var trueCounter = 0;
                var counter     = 0;
                foreach (var item in irisesTest)
                {
                    var outputValue = boostingAlgorithmus.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()));
            }
        }
Ejemplo n.º 4
0
        public void NaiveBayesIrisTest()
        {
            DataSetLoader dataSetLoader = new DataSetLoader();

            Console.WriteLine(" Reading DataSet.. ");
            var irisis = dataSetLoader.SelectIrises();

            for (double i = 0; i < 1; i = i + 1)
            {
                NaiveBayesClassifier naiveBayes =
                    new NaiveBayesClassifier(irisis, new LinearBayesKernel(irisis));
                var irisesTests = dataSetLoader.SelectIrises();
                var trueCounter = 0;
                var counter     = 0;
                foreach (var item in irisesTests)
                {
                    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()));
            }
        }
        public void IrisRadialBasisFunctionNeuronalNetworkClassifierTest()
        {
            DataSetLoader dataSetLoader = new DataSetLoader();

            Console.WriteLine(" Reading DataSet.. ");
            var irises = dataSetLoader.SelectNeuronalNetworkIrises();

            for (double i = 0; i < 1; i = i + 1)
            {
                OneHiddenLayerNeuronCounter        oneHiddenLayerNeuronCounter = new OneHiddenLayerNeuronCounter(4, 3, 3);
                RadialBasisFunctionNeuronalNetwork radialBasisFunctionNeuronalNetworkClassifier =
                    new RadialBasisFunctionNeuronalNetwork(oneHiddenLayerNeuronCounter, 10000, 0.7);
                radialBasisFunctionNeuronalNetworkClassifier.Train(irises);
                var irisesTest  = dataSetLoader.SelectIrises();
                var trueCounter = 0;
                var counter     = 0;
                foreach (var item in irisesTest)
                {
                    var    outputValue  = radialBasisFunctionNeuronalNetworkClassifier.Classify(item.Item1);
                    var    resultString = String.Empty;
                    double maxValue     = 0.0;
                    int    innerCounter = 1;
                    int    maxItem      = 0;
                    foreach (var value in outputValue.OutputValues)
                    {
                        if (value > maxValue)
                        {
                            maxValue = value;
                            maxItem  = innerCounter;
                        }
                        innerCounter++;
                    }
                    if (maxItem == item.Item2)
                    {
                        trueCounter++;
                    }
                    Debug.WriteLine(string.Format("Value {0} - Predicted {1} {2} {3} = {4}",
                                                  item.Item2,
                                                  Convert.ToDecimal(outputValue.OutputValues[0]),
                                                  Convert.ToDecimal(outputValue.OutputValues[1]),
                                                  Convert.ToDecimal(outputValue.OutputValues[2]),
                                                  (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()));
            }
        }
Ejemplo n.º 6
0
        public void kMetroidIrisTest()
        {
            DataSetLoader dataSetLoader = new DataSetLoader();

            Console.WriteLine(" Reading DataSet.. ");
            var irises = dataSetLoader.SelectClusteringIrises();
            kMetroidClustering kmeansClustering = new kMetroidClustering(irises, new EuclideMetric(), 100);
            var clusters       = kmeansClustering.Cluster(3);
            var clusterCounter = 0;
            Dictionary <int, int> clusterDictonary = new Dictionary <int, int>();

            foreach (var cluster in clusters)
            {
                Debug.WriteLine(string.Format("Cluster {0} - Count {1}", clusterCounter, cluster.Count));
                clusterDictonary.Add(clusterCounter, 0);
                clusterCounter++;
            }
            var irisesTest  = dataSetLoader.SelectIrises();
            var trueCounter = 0;
            var counter     = 0;

            foreach (var item in irisesTest)
            {
                var outputValue = kmeansClustering.CalculateClusterAffinity(item.Item1);
                Debug.WriteLine(string.Format("Value {0} - Predicted {1} - ClassificationItem {2}", item, outputValue, item.Item2 - 1));
                clusterDictonary[outputValue]++;
                counter++;
                trueCounter++;
            }
            clusterCounter = 0;
            foreach (var cluster in clusters)
            {
                var calculatedCluster = clusterDictonary[clusterCounter];
                Debug.WriteLine(string.Format("Cluster {0} - Original Count {1} - Calculated Count {2}",
                                              clusterCounter, cluster.Count, calculatedCluster));
                clusterCounter++;
            }
        }