public void Descriptor_Save_And_Load_Json()
        {
            var data        = Iris.Load();
            var description = Descriptor.Create <Iris>();
            // to populate dictionaries
            var examples = description.ToExamples(data);

            var file = GetPath();

            Register.Type <Iris>();
            var d = SaveAndLoadJson(description);

            Assert.Equal(description.Type, d.Type);
            Assert.Equal(description.Features.Length, d.Features.Length);
            for (int i = 0; i < description.Features.Length; i++)
            {
                Assert.Equal(description.Features[i].Type, d.Features[i].Type);
                Assert.Equal(description.Features[i].Name, d.Features[i].Name);
                Assert.Equal(description.Features[i].Start, d.Features[i].Start);
            }

            Assert.Equal(description.Label.Type, d.Label.Type);
            Assert.Equal(description.Label.Name, d.Label.Name);
            Assert.Equal(description.Label.Start, d.Label.Start);
        }
        public void Iris_Naive_Bayes_Save_And_Load_Test()
        {
            var data        = Iris.Load();
            var description = Descriptor.Create <Iris>();
            var generator   = new NaiveBayesGenerator(2);
            var model       = generator.Generate(description, data);

            Serialize(model);

            var lmodel = Deserialize <NaiveBayesModel>();
        }
        public void Save_And_Load_Iris_DT()
        {
            var data        = Iris.Load();
            var description = Descriptor.Create <Iris>();
            var generator   = new DecisionTreeGenerator(50);
            var model       = generator.Generate(description, data) as DecisionTreeModel;

            Serialize(model);
            var lmodel = Deserialize <DecisionTreeModel>();

            Assert.AreEqual(model.Hint, lmodel.Hint);
            AreEqual(model.Tree, lmodel.Tree, false);
        }
Esempio n. 4
0
        public void Iris_Naive_Bayes_Save_And_Load_Test_Json()
        {
            var data        = Iris.Load();
            var description = Descriptor.Create <Iris>();
            var generator   = new NaiveBayesGenerator(2);
            var model       = generator.Generate(description, data) as NaiveBayesModel;

            var file = GetPath();

            Register.Type <Iris>();
            var lmodel = SaveAndLoadJson(model);

            Assert.Equal(model.Root, lmodel.Root);
        }
        public void Save_And_Load_Iris_DT_Json()
        {
            var data        = Iris.Load();
            var description = Descriptor.Create <Iris>();
            var generator   = new DecisionTreeGenerator(50);
            var model       = generator.Generate(description, data) as DecisionTreeModel;

            var file = GetPath();

            Register.Type <Iris>();
            var lmodel = SaveAndLoadJson(model);

            Assert.Equal(model.Descriptor, lmodel.Descriptor);
            Assert.Equal(model.Hint, lmodel.Hint);
            Assert.Equal(model.Tree, lmodel.Tree);
        }
Esempio n. 6
0
 public void Iris_Tests()
 {
     // need to run multiple times since
     // this model is a bit more sensitive
     LearnerPrediction <Iris>(
         new NeuralNetworkGenerator(),
         Iris.Load(),
         new Iris
     {
         PetalWidth  = 0.5m,
         PetalLength = 2.3m,
         SepalLength = 2.1m,
         SepalWidth  = 2.1m
     },
         i => "Iris-setosa".Sanitize() == i.Class
         );
 }
Esempio n. 7
0
        public void IrisPrediction(IGenerator generator)
        {
            // should be Iris-Setosa
            Iris iris = new Iris
            {
                PetalWidth  = 0.5m,
                PetalLength = 2.3m,
                SepalLength = 2.1m,
                SepalWidth  = 2.1m
            };


            Prediction <Iris>(
                generator,                               // DT
                Iris.Load(),                             // training data
                iris,                                    // test object
                i => "Iris-setosa".Sanitize() == i.Class // should be true
                );
        }
Esempio n. 8
0
        public void IrisLearnerPrediction(IGenerator generator)
        {
            // should be Iris-Setosa
            Iris iris = new Iris
            {
                PetalWidth  = 0.5m,
                PetalLength = 2.3m,
                SepalLength = 2.1m,
                SepalWidth  = 2.1m
            };


            LearnerPrediction <Iris>(
                generator,
                Iris.Load(),
                iris,
                i => "Iris-setosa".Sanitize() == i.Class    // should be true
                );
        }
Esempio n. 9
0
        public void Iris_DT_and_Prediction()
        {
            var data        = Iris.Load();
            var description = Descriptor.Create <Iris>();
            var generator   = new DecisionTreeGenerator(50);
            var model       = generator.Generate(description, data);

            // should be Iris-Setosa
            Iris iris = new Iris
            {
                PetalWidth  = 0.5m,
                PetalLength = 2.3m,
                SepalLength = 2.1m,
                SepalWidth  = 2.1m
            };

            iris = model.Predict <Iris>(iris);
            Assert.AreEqual("Iris-setosa".Sanitize(), iris.Class);
        }
        public void Descriptor_Save_And_load()
        {
            var data        = Iris.Load();
            var description = Descriptor.Create <Iris>();
            // to populate dictionaries
            var examples = description.ToExamples(data);

            Serialize(description);
            var d = Deserialize <Descriptor>();

            Assert.Equal(description.Type, d.Type);
            Assert.Equal(description.Features.Length, d.Features.Length);
            for (int i = 0; i < description.Features.Length; i++)
            {
                Assert.Equal(description.Features[i].Type, d.Features[i].Type);
                Assert.Equal(description.Features[i].Name, d.Features[i].Name);
                Assert.Equal(description.Features[i].Start, d.Features[i].Start);
            }

            Assert.Equal(description.Label.Type, d.Label.Type);
            Assert.Equal(description.Label.Name, d.Label.Name);
            Assert.Equal(description.Label.Start, d.Label.Start);
        }
Esempio n. 11
0
        public void Iris_DT_and_Prediction_with_Learner()
        {
            var data = Iris.Load();

            var generator = new DecisionTreeGenerator(50)
            {
                Descriptor = Descriptor.Create <Iris>(),
                Hint       = 0
            };

            var lmodel = Learner.Learn(data, .80, 1000, generator);

            // should be Iris-Setosa
            Iris iris = new Iris
            {
                PetalWidth  = 0.5m,
                PetalLength = 2.3m,
                SepalLength = 2.1m,
                SepalWidth  = 2.1m
            };

            iris = lmodel.Model.Predict <Iris>(iris);
            Assert.AreEqual("Iris-setosa".Sanitize(), iris.Class);
        }
Esempio n. 12
0
        public void Iris_FluentDescriptor_DT_and_Prediction()
        {
            var data        = Iris.Load();
            var description = Descriptor.For <Iris>()
                              .Learn(x => x.Class)
                              .With(x => x.PetalLength)
                              .With(x => x.PetalWidth)
                              .With(x => x.SepalLength)
                              .With(x => x.SepalWidth);
            var generator = new NaiveBayesGenerator(2);
            var model     = generator.Generate(description, data);

            // should be Iris-Setosa
            Iris iris = new Iris
            {
                SepalLength = 2.1m,
                SepalWidth  = 2.2m,
                PetalWidth  = 0.5m,
                PetalLength = 2.3m,
            };

            iris = model.Predict <Iris>(iris);
            Assert.AreEqual("Iris-setosa".Sanitize(), iris.Class);
        }