public void Test_Manhatten_Distance_Metric()
 {
     //arrange
     int[] pixels1 = { -5, -6, -7 };
     int[] pixels2 = { -1, 8, 7 };
     ManhattanDistance md = new ManhattanDistance();
     //act
     var result = md.Between(pixels1, pixels2);
     //assert
     Assert.AreEqual(result, 32);
 }
 static void Main(string[] args)
 {
     var distance = new ManhattanDistance();
     var classifier = new BasicClassifier(distance);
     var trainingPath = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory() + "../../..").ToString(), "DigitsRecognizerTests", "datasamples", "digits", "trainingsample.csv");
     var training = DataReader.ReadObservations(trainingPath);
     classifier.Train(training);
     var validationPath = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory() + "../../..").ToString(), "DigitsRecognizerTests", "datasamples", "digits", "validationsample.csv");
     var validation = DataReader.ReadObservations(validationPath);
     var correct = Evaluator.Correct(validation, classifier);
     Console.WriteLine("Correctly classified: {0:P2}", correct);
     Console.ReadLine();
 }
 public void Test_model_Evaluator_scoring()
 {
     // 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
     var result = Evaluator.Score(trainingData[0], classifier);
     // assert
     Assert.AreEqual(result,1.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));
 }
        static void Main(string[] args)
        {
            var distance   = new ManhattanDistance();
            var classifier = new BasicClassifier(distance);
            var dataPath   = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\train.csv";

            Observation[] trainingdata = DataReader.ReadObservations(dataPath);
            //List<int> Selectionlist = new List<int>();
            //for (int i = 0; i < data.Length; i++)
            //{
            //    Selectionlist.Add(i);
            //}
            //Observation[] trainingData = new Observation[(int)(data.Length * .8)];
            //for (int i = 0; i < trainingData.Length; i++)
            //{
            //    Random r = new Random();
            //    int rInt = r.Next(0, Selectionlist.Count);
            //    trainingData[i] = data[rInt];
            //    Selectionlist.RemoveAt(rInt);
            //}

            classifier.Train(trainingdata);

            var testdataPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\test.csv";

            Observation[] testdata = DataReader.ReadObservations(testdataPath);

            Evaluator evaluator = new Evaluator();

            evaluator.Predict(testdata, classifier);
            StringBuilder stringBuilder = new StringBuilder();

            for (int i = 0; i < testdata.Length; i++)
            {
                writeProperty(stringBuilder, (i + 1).ToString(), true, false);
                writeProperty(stringBuilder, testdata[i].Label, false, true);
            }

            File.WriteAllText(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\sample_submission.csv", stringBuilder.ToString());


            Console.ReadLine();
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            var distance   = new ManhattanDistance();
            var classifier = new BasicClassifier(distance);

            var trainingPath = @"C:\Vikas\Knowledge\MachineLearning\DigitsRecognizer\trainingsample.csv";
            var training     = DataReader.ReadObservations(trainingPath);

            classifier.Train(training);

            var validationPath = @"C:\Vikas\Knowledge\MachineLearning\DigitsRecognizer\validationsample.csv";
            var validation     = DataReader.ReadObservations(validationPath);

            var correct = Evaluator.Correct(validation, classifier);

            Console.WriteLine("Correctly classified: {0:p2}", correct);

            Console.ReadLine();
        }