示例#1
0
        public void BackprobpagationLanguageTest()
        {
            var netMLString =
                "create classification backpropagation inputneurons = 16 outputneurons = 1 firsthiddenlayerneurons = 16 evolutions = 100 learningrate = 0.1 ";
            NetMLParser   netMLParser   = new NetMLParser();
            var           result        = netMLParser.Parse(netMLString);
            NetMLCreator  netMLCreator  = new NetMLCreator(result);
            DataSetLoader dataSetLoader = new DataSetLoader();
            var           data          = dataSetLoader.SelectAnimals();

            netMLCreator.Create(data);
            netMLCreator.Train();
            var testData    = dataSetLoader.SelectAnimals();
            var trueCounter = 0;
            var counter     = 0;

            foreach (var item in testData)
            {
                var outputValue = netMLCreator.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 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()));
            }
        }
示例#3
0
        public void SoundTest()
        {
            DataSetLoader dataSetLoader = new DataSetLoader();

            Console.WriteLine(" Reading DataSet.. ");
            var sound = dataSetLoader.SelectSounds(@"\Sounds\Unbenannt.wma");
        }
        public void SanFranciscoCrimeClassificationTest()
        {
            DataSetLoader dataSetLoader = new DataSetLoader();

            Console.WriteLine(" Reading DataSet.. ");
            var crimes = dataSetLoader.SelectCrimes();
            RandomForestClassifier decisionTreeClassifier =
                new RandomForestClassifier(crimes, new ShannonEntropySplitter(), new BaggingAlgorithmus(1));

            decisionTreeClassifier.Train();
            var crimeTests  = dataSetLoader.SelectCrimes();
            var trueCounter = 0;
            var counter     = 0;

            foreach (var item in crimeTests)
            {
                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()));
        }
示例#5
0
        public void CreditDataClassifyMethod()
        {
            DataSetLoader          dataSetLoader          = new DataSetLoader();
            var                    creditData             = dataSetLoader.SelectCreditData();
            var                    data                   = dataSetLoader.CalculatePercent(100, creditData);
            DecisionTreeClassifier decisionTreeClassifier =
                new DecisionTreeClassifier(data.Item1, new ShannonEntropySplitter());
            NaiveBayesClassifier naiveBayes =
                new NaiveBayesClassifier(data.Item1);
            var           list          = new List <NetML.Classification>();
            Kernel        kernel        = new LinearKernel();
            SVMClassifier SVMClassifier =
                new SVMClassifier(creditData, kernel, 0.001, 10.0);
            var neuronalCreditData = dataSetLoader.SelectNeuronalNetworksCreditData();
            NeuronalNetworkClassifier neuronalNetworkClassifier =
                new NeuronalNetworkClassifier(neuronalCreditData, 20, 2, 20, 5000, 0.1);

            list.Add(decisionTreeClassifier);
            list.Add(naiveBayes);
            list.Add(SVMClassifier);
            //list.Add(neuronalNetworkClassifier);
            Classifier classifier = new Classifier();

            classifier.Classify(list, creditData);
        }
示例#6
0
        public void NaivebayersLanguageTest()
        {
            var           netMLString   = "create classification naivebayers linearbayeskernel";
            NetMLCreator  netMLCreator  = new NetMLCreator(netMLString);
            DataSetLoader dataSetLoader = new DataSetLoader();
            var           data          = dataSetLoader.SelectAnimals();

            netMLCreator.Create(data);
            netMLCreator.Train();
            var testData    = dataSetLoader.SelectAnimals();
            var trueCounter = 0;
            var counter     = 0;

            foreach (var item in testData)
            {
                var outputValue = netMLCreator.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()));
        }
示例#7
0
        public void CreditDataRegressionTest()
        {
            DataSetLoader dataSetLoader = new DataSetLoader();

            Console.WriteLine(" Reading DataSet.. ");
            var        creditData          = dataSetLoader.SelectCreditData();
            Regression loggistigRegression =
                new Regression(creditData, new NetML.LogisticRegression.LogisticCostFunction());

            loggistigRegression.Train();
            var creditDataTest = dataSetLoader.SelectCreditData();
            var trueCounter    = 0;
            var counter        = 0;

            foreach (var item in creditDataTest)
            {
                var outputValue = loggistigRegression.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()));
        }
        public void SanFranciscoCrimeSVMClassificationDataSetTest()
        {
            DataSetLoader dataSetLoader = new DataSetLoader();

            Console.WriteLine(" Reading DataSet.. ");
            var           crimes        = dataSetLoader.SelectCrimes();
            Kernel        kernel        = new GaussianKernel(0.9);
            SVMClassifier svmClassifier =
                new SVMClassifier(crimes, kernel);

            svmClassifier.Train();
            var crimeTests  = dataSetLoader.SelectCrimes();
            var trueCounter = 0;
            var counter     = 0;

            foreach (var item in crimeTests)
            {
                var outputValue = svmClassifier.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()));
        }
示例#9
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()));
        }
示例#10
0
        public void AnimalDualPerceptronTest()
        {
            DataSetLoader dataSetLoader = new DataSetLoader();

            Console.WriteLine(" Reading DataSet.. ");
            var animals = dataSetLoader.SelectAnimals();

            for (double i = 0; i < 1; i = i + 1)
            {
                Kernel kernel = new LinearKernel();
                DualPerceptronClassifier dualPerceptronClassifier = new DualPerceptronClassifier(animals, kernel);
                dualPerceptronClassifier.Train();
                var animalsTest = dataSetLoader.SelectAnimals();
                var trueCounter = 0;
                var counter     = 0;
                foreach (var item in animalsTest)
                {
                    var outputValue = dualPerceptronClassifier.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()));
            }
        }
示例#11
0
        public void AnimalBoostingTrainAndClassify8020Test()
        {
            DataSetLoader dataSetLoader = new DataSetLoader();

            Console.WriteLine(" Reading DataSet.. ");
            var animals = dataSetLoader.SelectTrainingAnimals(90);

            for (double i = 0; i < 1; i = i + 1)
            {
                BoostingAlgorithmus boostingAlgorithmus =
                    new BoostingAlgorithmus(10);
                boostingAlgorithmus.Train(animals, new ShannonEntropySplitter());
                var animalsTest = dataSetLoader.SelectSelectingAnimals(10);
                var trueCounter = 0;
                var counter     = 0;
                foreach (var item in animalsTest)
                {
                    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()));
            }
        }
示例#12
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()));
            }
        }
示例#13
0
        public void CreditDataNaiveBayesTest()
        {
            DataSetLoader dataSetLoader = new DataSetLoader();

            Console.WriteLine(" Reading DataSet.. ");
            var creditData = dataSetLoader.SelectCreditData();
            NaiveBayesClassifier naiveBayes =
                new NaiveBayesClassifier(creditData);
            var creditDataTest = dataSetLoader.SelectCreditData();
            var trueCounter    = 0;
            var counter        = 0;

            foreach (var item in creditDataTest)
            {
                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("Data {0} - True {1} Verhältnis: {2}",
                                          counter.ToString(), trueCounter.ToString(), (Convert.ToDouble(trueCounter) / Convert.ToDouble(counter)).ToString()));
        }
示例#14
0
        public void AnimalClassifyMethod()
        {
            DataSetLoader          dataSetLoader          = new DataSetLoader();
            var                    animals                = dataSetLoader.SelectAnimals();
            var                    data                   = dataSetLoader.CalculatePercent(50, animals);
            DecisionTreeClassifier decisionTreeClassifier =
                new DecisionTreeClassifier(data.Item1, new ShannonEntropySplitter());
            NaiveBayesClassifier naiveBayes =
                new NaiveBayesClassifier(data.Item1);
            var           list   = new List <NetML.Classification>();
            Kernel        kernel = new LinearKernel();
            SVMClassifier animalSVMClassifier =
                new SVMClassifier(animals, kernel, 0.001, 10.0);
            var neuronalAnimals = dataSetLoader.SelectNeuronalNetworkAnimals();
            NeuronalNetworkClassifier neuronalNetworkClassifier =
                new NeuronalNetworkClassifier(neuronalAnimals, 16, 7, 16, 500, 0.1);

            list.Add(decisionTreeClassifier);
            list.Add(naiveBayes);
            list.Add(animalSVMClassifier);
            list.Add(neuronalNetworkClassifier);
            Classifier classifier = new Classifier();

            classifier.Classify(list, data.Item2);
        }
        public void CreditDataRadialBasisFunctionNeuronalNetworkClassifierTest()
        {
            DataSetLoader dataSetLoader = new DataSetLoader();

            Console.WriteLine(" Reading DataSet.. ");
            var creditData = dataSetLoader.SelectCreditData();

            for (double i = 0; i < 1; i = i + 1)
            {
                OneHiddenLayerNeuronCounter        oneHiddenLayerNeuronCounter = new OneHiddenLayerNeuronCounter(6, 1, 36);
                RadialBasisFunctionNeuronalNetwork radialBasisFunctionNeuronalNetworkClassifier =
                    new RadialBasisFunctionNeuronalNetwork(oneHiddenLayerNeuronCounter, 5000, 0.7);
                radialBasisFunctionNeuronalNetworkClassifier.Train(creditData);
                var creditDataTest = dataSetLoader.SelectCreditData();
                var trueCounter    = 0;
                var counter        = 0;
                foreach (var item in creditDataTest)
                {
                    var outputValue = radialBasisFunctionNeuronalNetworkClassifier.Classify(item.Item1);
                    var value       = (outputValue.OutputValues[0] > 0.5) ? 1.0 : 0.0;
                    if (value == item.Item2)
                    {
                        trueCounter++;
                    }
                    Debug.WriteLine(string.Format("Value {0} - Predicted {1} = {2}",
                                                  item.Item2, Convert.ToDecimal(outputValue.OutputValues[0]),
                                                  (value == 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 AnimalRadialBasisFunctionNeuronalNetworkClassifierTest()
        {
            DataSetLoader dataSetLoader = new DataSetLoader();

            Console.WriteLine(" Reading DataSet.. ");
            var animals = dataSetLoader.SelectNeuronalNetworkAnimals();

            for (double i = 0; i < 1; i = i + 1)
            {
                OneHiddenLayerNeuronCounter        oneHiddenLayerNeuronCounter = new OneHiddenLayerNeuronCounter(16, 8, 32);
                RadialBasisFunctionNeuronalNetwork radialBasisFunctionNeuronalNetworkClassifier =
                    new RadialBasisFunctionNeuronalNetwork(oneHiddenLayerNeuronCounter, 10000, 0.5);
                radialBasisFunctionNeuronalNetworkClassifier.Train(animals);
                var animalsTest = dataSetLoader.SelectAnimals();
                var trueCounter = 0;
                var counter     = 0;
                foreach (var item in animalsTest)
                {
                    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} {5} {6} {7} = {8}",
                                                  item.Item2,
                                                  Convert.ToDecimal(outputValue.OutputValues[0]),
                                                  Convert.ToDecimal(outputValue.OutputValues[1]),
                                                  Convert.ToDecimal(outputValue.OutputValues[2]),
                                                  Convert.ToDecimal(outputValue.OutputValues[3]),
                                                  Convert.ToDecimal(outputValue.OutputValues[4]),
                                                  Convert.ToDecimal(outputValue.OutputValues[5]),
                                                  Convert.ToDecimal(outputValue.OutputValues[6]),
                                                  (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()));
            }
        }
        public void SanFranciscoCrimeClassificationTestDataSetTest()
        {
            DataSetLoader dataSetLoader = new DataSetLoader();

            Console.WriteLine(" Reading DataSet.. ");
            var crimes = dataSetLoader.SelectNeuronalNetworkCrimes();
            //DecisionTreeClassifier decisionTreeClassifier =
            //new DecisionTreeClassifier(crimes, new ShannonEntropySplitter());
            NeuronalNetworkClassifier neuronalNetworkClassifier =
                new NeuronalNetworkClassifier(crimes, 2, 38, 2, 5000, 0.1);

            //Kernel kernel = new LinearKernel();
            //NaiveBayesClassifier naiveBayes =
            //        new NaiveBayesClassifier(crimes);
            neuronalNetworkClassifier.Train();
            var crimeTests  = dataSetLoader.SelectCrimes();
            var trueCounter = 0;
            var counter     = 0;

            foreach (var item in crimeTests)
            {
                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("Data {0} - True {1} Verhältnis: {2}",
                                          counter.ToString(), trueCounter.ToString(), (Convert.ToDouble(trueCounter) / Convert.ToDouble(counter)).ToString()));
        }
示例#18
0
        public void MushroomsNeuronalNetworkMachineTrainAndClassify8020Test()
        {
            DataSetLoader dataSetLoader = new DataSetLoader();

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

            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.SelectNeuronalNetworksSelectingMushroom(20);
                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()));
            }
        }
示例#19
0
        public void AnimalNeuronalNetworkClassifierTest()
        {
            DataSetLoader dataSetLoader = new DataSetLoader();

            Console.WriteLine(" Reading DataSet.. ");
            var animals = dataSetLoader.SelectNeuronalNetworkAnimals();

            for (double i = 0; i < 1; i = i + 1)
            {
                NeuronalNetworkClassifier neuronalNetworkClassifier =
                    new NeuronalNetworkClassifier(animals, 16, 7, 16, 900, 0.1, NeuronalNetworkMode.Standard);
                neuronalNetworkClassifier.Train();
                var animalsTest = dataSetLoader.SelectAnimals();
                var trueCounter = 0;
                var counter     = 0;
                foreach (var item in animalsTest)
                {
                    var    outputValue  = neuronalNetworkClassifier.ClassifiyMultibleResultValue(item.Item1);
                    var    resultString = String.Empty;
                    double maxValue     = 0.0;
                    int    innerCounter = 1;
                    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()));
            }
        }
示例#20
0
        public void ClusteringLanguageTest()
        {
            var netMLString =
                "create clustering kmetroids euclidmetric ";
            NetMLParser   netMLParser   = new NetMLParser();
            var           result        = netMLParser.Parse(netMLString);
            NetMLCreator  netMLCreator  = new NetMLCreator(result);
            DataSetLoader dataSetLoader = new DataSetLoader();
            var           irises        = dataSetLoader.SelectClusteringIrises();

            netMLCreator.Create(irises);
            var clusters       = netMLCreator.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.SelectClusteringIrises();
            var trueCounter = 0;
            var counter     = 0;

            foreach (var item in irisesTest)
            {
                var outputValue = netMLCreator.CalculateClusterAffinity(item);
                Debug.WriteLine(string.Format("Value {0} - Predicted {1}", item, outputValue));
                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++;
            }
        }
示例#21
0
        public void kMeansIrisTest()
        {
            DataSetLoader dataSetLoader = new DataSetLoader();

            Console.WriteLine(" Reading DataSet.. ");
            var irises = dataSetLoader.SelectClusteringIrises();
            kMeansClustering kmeansClustering = new kMeansClustering(irises, new MaximumMetric());
            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.SelectClusteringIrises();
            var trueCounter = 0;
            var counter     = 0;

            foreach (var item in irisesTest)
            {
                var outputValue = kmeansClustering.CalculateClusterAffinity(item);
                Debug.WriteLine(string.Format("Value {0} - Predicted {1}", item, outputValue));
                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++;
            }
            //var centroids = kmeansClustering.centroids;
            //var clusters = kmeansClustering.ClusterWithCentroid(4);
        }