Esempio n. 1
0
        //[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 }");
        }
Esempio n. 2
0
        //[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 }");
        }