public void should_predict_nearest_label(List <DataPoint> dataPoints, List <int> pixels)
        {
            classifier.Train(dataPoints);
            distance.Between(dataPoints[0].Pixels, pixels).Returns(3);
            distance.Between(dataPoints[1].Pixels, pixels).Returns(1);
            distance.Between(dataPoints[2].Pixels, pixels).Returns(8);

            var result = classifier.Predict(pixels);

            result.Should().Be(dataPoints[1].Label);
        }
Esempio n. 2
0
        public void Test_Base_Classifier_training()
        {
            //arrange
            var    distance     = new ManhattanDistance();
            var    classifier   = new BasicClassifier(distance);
            string trainingPath = Path.Combine(TestContext.DeploymentDirectory, "digits", "trainingsample.csv");
            var    trainingData = DataReader.ReadObservations(trainingPath);

            classifier.Train(trainingData);
            //act
            string labelResult = classifier.Predict(trainingData[0].Pixels);

            //assert
            Assert.IsFalse(string.IsNullOrEmpty(labelResult));
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            IClassifier classifier      = new BasicClassifier();
            ReadHelper  trainingSamples = new ReadHelper("trainingsample.csv");
            var         trainingSample  = trainingSamples.Records;

            Console.WriteLine("Training done");

            //Console.WriteLine("Which image(as row of file) would you like to identify?");
            //var k = int.Parse(Console.ReadLine());

            ReadHelper validationSamples = new ReadHelper("validationsample.csv");
            var        recordsToValidate = validationSamples.Records;

            //var recordToValidate = validationSamples.Records[k];
            Console.WriteLine("Validate done");

            int notRecognized = recordsToValidate.Length;

            for (int k = 0; k < recordsToValidate.Length; k++)
            {
                var recordToValidate = validationSamples.Records[k];
                var result           = classifier.Predict(recordToValidate, trainingSamples.Records).ToArray();
                var sortedResult     = result.OrderBy(x => x.Distance).First();
                if (sortedResult.Number != recordToValidate.Number)
                {
                    Console.WriteLine($"Probably it is {sortedResult.Number}, it's distance is {Math.Floor(sortedResult.Distance)}");
                    Console.WriteLine($"It should be: {recordToValidate.Number}");
                    notRecognized--;
                }
            }
            decimal accuracy = (notRecognized / 500m) * 100;

            Console.WriteLine($"Accuracy: {accuracy}%");
            Console.ReadLine();
        }