Exemplo n.º 1
0
        public void TestNaiveBayesOnPrepAttachData()
        {
            var model = NaiveBayesTests.TrainModel(PrepAttachDataUtility.CreateTrainingStream());

            Assert.NotNull(model);

            PrepAttachDataUtility.TestModel(model, 0.7897994553107205);
        }
        public void TestNaiveBayes4()
        {
            var model   = NaiveBayesTests.TrainModel();
            var label   = "politics";
            var context = new string[0];
            var e       = new Event(label, context);

            NaiveBayesTests.TestModel(model, e, 7.0 / 12.0);
        }
        public void TestNaiveBayes3()
        {
            var model   = NaiveBayesTests.TrainModel();
            var label   = "politics";
            var context = new[] { "bow=united" };
            var e       = new Event(label, context);

            // NaiveBayesTests.TestModel(model, e, 2.0 / 3.0);          // Expected value without smoothing
            NaiveBayesTests.TestModel(model, e, 0.6655036407766989);    // Expected value with smoothing
        }
        public void TestNaiveBayes2()
        {
            var model   = NaiveBayesTests.TrainModel();
            var label   = "sports";
            var context = new[] { "bow=manchester", "bow=united" };
            var e       = new Event(label, context);

            // NaiveBayesTests.TestModel(model, e, 1.0);                // Expected value without smoothing
            NaiveBayesTests.TestModel(model, e, 0.9658833555831029);    // Expected value with smoothing
        }
        public void TestNaiveBayes1()
        {
            var model   = NaiveBayesTests.TrainModel();
            var label   = "politics";
            var context = new[] { "bow=united", "bow=nations" };
            var e       = new Event(label, context);

            //NaiveBayesTests.TestModel(model, e, 1.0);                 // Expected value without smoothing
            NaiveBayesTests.TestModel(model, e, 0.9681650180264167);    // Expected value with smoothing
        }
        public void TestTextModelPersistence()
        {
            var model = NaiveBayesTests.TrainModel();

            AbstractModel deserialized;

            using (var data = new MemoryStream()) {
                using (var writer = new PlainTextNaiveBayesModelWriter(model, new UnclosableStream(data)))
                    writer.Persist();

                data.Seek(0, SeekOrigin.Begin);

                using (var reader = new PlainTextNaiveBayesModelReader(data)) {
                    deserialized = reader.GetModel();
                }
            }

            Assert.NotNull(deserialized);
            Assert.IsInstanceOf <NaiveBayesModel>(deserialized);
        }