public void Setup() { threeClassDataset = ArffDataSet.Create <PositivityType>("Test"); threeClassDataset.UseTotal = true; twoClassDataset = ArffDataSet.CreateSimple("Test"); twoClassDataset.UseTotal = true; twoClassDataset.Header.RegisterNominalClass("Positive", "Negative"); for (int i = 0; i < 20; i++) { var positive = threeClassDataset.AddDocument(); positive.Class.Value = PositivityType.Positive; positive.AddRecord("Good"); positive = twoClassDataset.AddDocument(); positive.Class.Value = "Positive"; positive.AddRecord("Good"); var negative = threeClassDataset.AddDocument(); negative.Class.Value = PositivityType.Negative; negative.AddRecord("Bad"); negative = twoClassDataset.AddDocument(); negative.Class.Value = "Negative"; negative.AddRecord("Bad"); } }
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); }
public void CreateGrid(KernelType kernel, int instances, int features, int gammas, int c, bool shrink) { for (int i = 0; i < features; i++) { dataSet.Header.RegisterNumeric(i.ToString()); } for (int i = 0; i < instances; i++) { var review = dataSet.AddDocument(); review.Class.Value = "One"; review.AddRecord("Record").Value = 0.1; } TrainingHeader header = TrainingHeader.Create(kernel, SvmType.C_SVC); var result = factory.Create(header, dataSet) as GridParameterSelection; Assert.AreEqual(3, result.SearchParameters.Folds); Assert.AreEqual(gammas, result.SearchParameters.Gamma.Length); Assert.AreEqual(c, result.SearchParameters.C.Length); Assert.AreEqual(kernel, result.SearchParameters.Default.KernelType); Assert.AreEqual(shrink, result.SearchParameters.Default.Shrinking); Assert.AreEqual(SvmType.C_SVC, result.SearchParameters.Default.SvmType); }