static void Main(string[] args) { // Classifier setup var distance = new ManhattanDistance(); var classifier = new BasicClassifier(distance); // Training string dataPath = @"../data/trainingsample.csv"; Console.WriteLine($"Reading training data from {dataPath}"); Observation[] trainingSet = DataReader.ReadObservations(dataPath); classifier.Train(trainingSet); // Validation string validationPath = @"../data/validationsample.csv"; Console.WriteLine($"Reading validation data from {validationPath}"); Observation[] validationSet = DataReader.ReadObservations(validationPath); Console.WriteLine("Validating the classifier..."); var correct = Evaluator.Correct(validationSet, classifier); Console.WriteLine("Classification score: {0:P2}", correct); Console.ReadLine(); }
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); }
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)); }
private static BasicClassifier GetTrainingClassifier() { var baseDirectory = @"C:\Users\pavel\Documents\Visual Studio 2017\Projects\DigitRecognizer\DigitRecognizer\"; var distance = new EuclidianDistance(); var classifier = new BasicClassifier(distance); var trainingPath = $@"{baseDirectory}train.csv"; var training = DataReader.ReadObservations(trainingPath); classifier.Train(training); return(classifier); }
static void Main(string[] args) { var distance = new ManhattanDistance(); var classifier = new BasicClassifier(distance); var trainingPath = "./data/train_truncated.csv"; var training = DataReader.ReadObservations(trainingPath); classifier.Train(training); var validationPath = "./data/validate_truncated.csv"; var validation = DataReader.ReadObservations(validationPath); var correct = Evaluator.Correct(validation, classifier); Console.WriteLine("Correctly classified {0:P2}", correct); }
static void Main(string[] args) { var distance = new ManhattanDistance(); var classifier = new BasicClassifier(distance); var trainingPath = @"C:\Users\ifeanyi\Documents\visual studio 2013\Projects\MLImageDigitizer\MLImageDigitizer\Data\trainingdata.csv"; var training = DataReader.ReadObservations(trainingPath); classifier.Train(training); var validationPath = @"C:\Users\ifeanyi\Documents\visual studio 2013\Projects\MLImageDigitizer\MLImageDigitizer\Data\validationdata.csv"; var validation = DataReader.ReadObservations(validationPath); var correct = Evaluator.Correct(validation, classifier); Console.WriteLine("Correctly classified: {0:P2}", correct); Console.ReadLine(); }
static void Main(string[] args) { var classifier = new BasicClassifier(); var trainingPath = String.Format("{0}\\trainingsample.csv",System.IO.Directory.GetCurrentDirectory()); var validationPath = String.Format("{0}\\validationsample.csv", System.IO.Directory.GetCurrentDirectory()); Console.WriteLine("Training Data..."); var training = DigitDataReader.ReadObservations(trainingPath); classifier.Train(training); var validation = DigitDataReader.ReadObservations(validationPath); var correctAverage = Evaluator.Correct(validation, classifier); Console.WriteLine("Correctly classified: {0:P2}", correctAverage); Console.WriteLine("Press Enter to exit..."); Console.ReadLine(); }
static void Main(string[] args) { var distance = new ManhattanDistance(); var classifier = new BasicClassifier(distance); var dataPath = @"/Users/espen/git/ML-book-experiments/DigitsRecognizer/data/"; var trainingPath = dataPath + "trainingsample.csv"; var trainingSet = DataReader.ReadObservations(trainingPath); classifier.Train(trainingSet); var validationPath = dataPath + "validationsample.csv"; var validationSet = DataReader.ReadObservations(validationPath); var correct = Evaluator.Correct(validationSet, classifier); Console.WriteLine($"Correctly classified: {correct:P2}"); Console.WriteLine("Press enter to exit."); Console.ReadLine(); }
static void Main(string[] args) { var distance = new ManhattanDistance(); var classifier = new BasicClassifier(distance); //@:写路径字符串可以让字符串不需要转义,否则需要写两个\\ //读取训练集 var trainingPath = @"D:\SojS\machine-learning\machine-learning-projects-for-dot-net-developers\chapter-1\DigitsRecognizer\Data\trainingsample.csv"; var training = DataReader.ReadObservations(trainingPath); //训练基本分类器 classifier.Train(training); //读取验证集 var validationPath = @"D:\SojS\machine-learning\machine-learning-projects-for-dot-net-developers\chapter-1\DigitsRecognizer\Data\validationsample.csv"; var validation = DataReader.ReadObservations(validationPath); //验证分类器 var correct = Evaluator.Correct(validation, classifier); Console.WriteLine("{0:P2}", correct); Console.ReadLine(); }