private static void SaveArff(IArffDataSet arff, Stream outStream)
 {
     using (StreamWriter writer = new StreamWriter(outStream))
     {
         arff.Save(writer);
         outStream.Flush();
     }
 }
        public async Task TestTwoClass()
        {
            var         problemFactory = new ProblemFactory(twoClassDataset);
            SvmTraining training       = new SvmTraining(problemFactory, twoClassDataset);
            var         parameters     = training.SelectParameters(TrainingHeader.CreateDefault(), CancellationToken.None);
            var         results        = await training.Train(parameters).ConfigureAwait(false);

            var file = Path.Combine(TestContext.CurrentContext.TestDirectory, "data.arff");

            threeClassDataset.Save(file);
            var        testFile = ArffDataSet.LoadSimple(file);
            SvmTesting testing  = new SvmTesting(results.Model, problemFactory);
            var        result   = testing.Test(testFile, Path.Combine(TestContext.CurrentContext.TestDirectory, "."));

            Assert.AreEqual(1, result);
        }
예제 #3
0
        public void Save(string path)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(path));
            }

            log.LogInformation("Saving {0}...", path);
            var fileName = $"{Word.Text.CreatePureLetterText()}.arff";

            path = Path.Combine(path, fileName);
            IArffDataSet arff = ArffDataSet.Create <PositivityType>(Word.Text);

            arff.UseTotal = true;
            foreach (WordsContext vector in Vectors)
            {
                IArffDataRow review = arff.AddDocument();
                review.Class.Value = vector.SentimentValue > 0
                    ? PositivityType.Positive
                    : PositivityType.Negative;
                foreach (WordEx wordItem in vector.Words)
                {
                    if (!wordItem.IsAspect &&
                        wordItem.Value == 0)
                    {
                        continue;
                    }

                    DataRecord addedWord = review.AddRecord(wordItem.Text);
                    addedWord.Value = addedWord.Total;
                }
            }

            arff.Save(path);
            log.LogInformation("Saving {0} Completed.", path);
        }