Example #1
0
 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();
 }
Example #2
0
        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");
        }
Example #3
0
        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");
        }
Example #4
0
        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);
        }
Example #5
0
 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()
     ;
 }