예제 #1
0
 public void TestNNMF()
 {
     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().NNMF(_lap, 2);
     var clusterLabels = clusters.Select(d => d.Select(d2 => data[d2]).ToArray()).ToList();
 }
예제 #2
0
        public void TestDecisionTree()
        {
            var stringTableBuilder = new StringTableBuilder();
            var data = NaiveBayesTests.GetSimpleChineseSet(stringTableBuilder).
                       ConvertToWeightedIndexList(false).Vectorise().ConvertToTable(false);
            var model      = data.TrainDecisionTree();
            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]).GetBestClassification() == "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);
        }