예제 #1
0
파일: SVMTests.cs 프로젝트: xtellurian/numl
        //[Fact]
        public void Test_SVM_Email_Classification()
        {
            var training_Data = System.IO.File.ReadAllLines("Data\\Emails\\Training_Data.txt")
                                .Select(s => s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToVector(f => double.Parse(f.Trim()))).ToMatrix();

            var training_Labels = System.IO.File.ReadAllLines("Data\\Emails\\Training_Labels.txt")
                                  .Select(s => double.Parse(s.Trim())).ToVector();

            var test_Data = System.IO.File.ReadAllLines("Data\\Emails\\Test_Data.txt")
                            .Select(s => s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToVector(f => double.Parse(f.Trim()))).ToMatrix();

            var test_Labels = System.IO.File.ReadAllLines("Data\\Emails\\Test_Labels.txt")
                              .Select(s => double.Parse(s.Trim())).ToVector();

            var generator = new Supervised.SVM.SVMGenerator()
            {
                C                 = 0.1,
                MaxIterations     = 5,
                SelectionFunction = new Supervised.SVM.Selection.RandomSetSelection()
            };

            var model = generator.Generate(training_Data, training_Labels);

            Vector predictions = new Vector(test_Labels.Count());

            for (int x = 0; x < test_Labels.Count(); x++)
            {
                predictions[x] = model.Predict(test_Data[x]);
            }

            var score = numl.Supervised.Score.ScorePredictions(predictions, test_Labels);

            Console.WriteLine($"SVM Model\n: { score }");
        }
예제 #2
0
파일: SVMTests.cs 프로젝트: sethjuarez/numl
        //[Fact]
        public void Test_SVM_Email_Classification()
        {
            var training_Data = System.IO.File.ReadAllLines("Data\\Emails\\Training_Data.txt")
                                    .Select(s => s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToVector(f => double.Parse(f.Trim()))).ToMatrix();

            var training_Labels = System.IO.File.ReadAllLines("Data\\Emails\\Training_Labels.txt")
                                    .Select(s => double.Parse(s.Trim())).ToVector();

            var test_Data = System.IO.File.ReadAllLines("Data\\Emails\\Test_Data.txt")
                                    .Select(s => s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToVector(f => double.Parse(f.Trim()))).ToMatrix();

            var test_Labels = System.IO.File.ReadAllLines("Data\\Emails\\Test_Labels.txt")
                                    .Select(s => double.Parse(s.Trim())).ToVector();

            var generator = new Supervised.SVM.SVMGenerator()
            {
                C = 0.1,
                MaxIterations = 5,
                SelectionFunction = new Supervised.SVM.Selection.RandomSetSelection()
            };

            var model = generator.Generate(training_Data, training_Labels);

            Vector predictions = new Vector(test_Labels.Count());
            for (int x = 0; x < test_Labels.Count(); x++)
            {
                predictions[x] = model.Predict(test_Data[x]);
            }

            var score = numl.Supervised.Score.ScorePredictions(predictions, test_Labels);

            Console.WriteLine($"SVM Model\n: { score }");
        }