public void TestNNMF() { var stringTableBuilder = new StringTableBuilder(); var data = NaiveBayesTests.GetSimpleChineseSet(stringTableBuilder).ConvertToSparseVectors(false).Vectorise(true).ToDictionary(d => _lap.Create(d.Data), d => d.Classification); var clusters = data.Select(d => d.Key).ToList().NNMF(_lap, 2); var clusterLabels = clusters.Select(d => d.Select(d2 => data[d2]).ToArray()).ToList(); }
public void TestRandomForest() { var stringTableBuilder = new StringTableBuilder(); var data = NaiveBayesTests.GetSimpleChineseSet(stringTableBuilder).ConvertToWeightedIndexList(false).ConvertToTable(); var model = data.TrainRandomForest(); var classifier = model.CreateClassifier(); var testRows = data.GetRows(new[] { 0, data.RowCount - 1 }); Assert.IsTrue(classifier.Classify(testRows[0]).GetBestClassification() == "china"); //Assert.IsTrue(classifier.Classify(testRows[1]).First() == "japan"); }
public void TestDecisionTree() { var stringTableBuilder = new StringTableBuilder(); var data = NaiveBayesTests.GetSimpleChineseSet(stringTableBuilder).ConvertToSparseVectors(false).ConvertToTable(); var model = data.TrainDecisionTree(); var classifier = model.CreateClassifier(); var testRows = data.GetRows(new[] { 0, data.RowCount - 1 }); Assert.IsTrue(classifier.Classify(testRows[0]).First() == "china"); Assert.IsTrue(classifier.Classify(testRows[1]).First() == "japan"); }
public void TestTFIDF() { var stringTableBuilder = new StringTableBuilder(); var data = NaiveBayesTests.GetSimpleChineseSet(stringTableBuilder); Assert.AreEqual(data.Count, 4); Assert.AreEqual(data.First().Data.Count, 3); var set = data.ConvertToWeightedIndexList(true); Assert.AreEqual(set.Count, 2); Assert.AreEqual(set.First().Data.Count, 4); var tfidf = set.TFIDF(); Assert.AreEqual(tfidf.Count, 2); Assert.AreEqual(tfidf.First().Data.Count, 4); }
public void TestKMeans() { var stringTableBuilder = new StringTableBuilder(); var data = NaiveBayesTests.GetSimpleChineseSet(stringTableBuilder) .ConvertToWeightedIndexList(false) .Vectorise() .ToDictionary(d => _lap.CreateVector(d.Data), d => d.Classification) ; var clusters = data .Select(d => d.Key) .ToList() .KMeans(2) ; var clusterLabels = clusters .Select(d => d.Select(d2 => data[d2]).ToArray()) .ToList() ; }