Пример #1
0
        public void DataTransformers()
        {
            PakiraDecisionTreeGenerator pakiraGenerator = PakiraGeneratorTests.CreatePakiraGeneratorInstance();
            TrainData trainData = new TrainData();

            trainData = trainData.AddSample(ImmutableList.CreateRange(new double[] { 2, 3 }), 42);
            trainData = trainData.AddSample(ImmutableList.CreateRange(new double[] { 120, 140 }), 54);
            trainData = trainData.AddSample(ImmutableList.CreateRange(new double[] { 190, 200 }), 42);

            PassThroughTransformer      passThroughTransformer      = new PassThroughTransformer();
            MeanDistanceDataTransformer meanDistanceDataTransformer = new MeanDistanceDataTransformer();

            Converter <IEnumerable <double>, IEnumerable <double> > dataTransformers = null;

            dataTransformers += passThroughTransformer.ConvertAll;
            dataTransformers += meanDistanceDataTransformer.ConvertAll;

            pakiraGenerator.CertaintyScore = 10.0;

            PakiraDecisionTreeModel pakiraDecisionTreeModel = new PakiraDecisionTreeModel(dataTransformers, trainData.Samples[0]);

            pakiraDecisionTreeModel = pakiraGenerator.Generate(pakiraDecisionTreeModel, trainData);

            pakiraDecisionTreeModel.Tree.Root.ShouldNotBeNull();

            pakiraDecisionTreeModel.PredictNode(trainData.Samples[0]).Value.ShouldBe(trainData.Labels[0]);
            pakiraDecisionTreeModel.PredictNode(trainData.Samples[1]).Value.ShouldBe(trainData.Labels[1]);
            pakiraDecisionTreeModel.PredictNode(trainData.Samples[2]).Value.ShouldBe(trainData.Labels[2]);

            // The data transformers should allow to produce a very shallow tree
            pakiraDecisionTreeModel.Tree.GetNodes().Count().ShouldBe(3);
        }
Пример #2
0
        public void DeepTree()
        {
            PakiraDecisionTreeGenerator pakiraGenerator = PakiraGeneratorTests.CreatePakiraGeneratorInstance();
            TrainData trainData = new TrainData();

            trainData = trainData.AddSample(ImmutableList.CreateRange(new double[] { 2, 3 }), 42);
            trainData = trainData.AddSample(ImmutableList.CreateRange(new double[] { 250, 254 }), 54);
            trainData = trainData.AddSample(ImmutableList.CreateRange(new double[] { 250, 255 }), 42);
            trainData = trainData.AddSample(ImmutableList.CreateRange(new double[] { 251, 253 }), 6);
            trainData = trainData.AddSample(ImmutableList.CreateRange(new double[] { 251, 254 }), 9);
            trainData = trainData.AddSample(ImmutableList.CreateRange(new double[] { 1, 2 }), 96);
            trainData = trainData.AddSample(ImmutableList.CreateRange(new double[] { 2, 1 }), 97);
            trainData = trainData.AddSample(ImmutableList.CreateRange(new double[] { 2, 2 }), 98);
            trainData = trainData.AddSample(ImmutableList.CreateRange(new double[] { 3, 2 }), 99);

            PakiraDecisionTreeModel pakiraDecisionTreeModel = new PakiraDecisionTreeModel(trainData.Samples[0]);

            pakiraGenerator.MinimumSampleCount = 100;

            pakiraDecisionTreeModel = pakiraGenerator.Generate(pakiraDecisionTreeModel, trainData);

            pakiraDecisionTreeModel.Tree.Root.ShouldNotBeNull();

            pakiraDecisionTreeModel.Tree.GetNodes().Count().ShouldBeGreaterThanOrEqualTo(15, "If the test fails because of this, the number can be reduced as long as it stays 'high'. Instead, the tree depth could also be validated.");
            pakiraDecisionTreeModel.PredictNode(trainData.Samples[0]).Value.ShouldBe(trainData.Labels[0]);
            pakiraDecisionTreeModel.PredictNode(trainData.Samples[1]).Value.ShouldBe(trainData.Labels[1]);
            pakiraDecisionTreeModel.PredictNode(trainData.Samples[2]).Value.ShouldBe(trainData.Labels[2]);
        }
Пример #3
0
        public void CertaintyScore()
        {
            PakiraDecisionTreeGenerator pakiraGenerator = PakiraGeneratorTests.CreatePakiraGeneratorInstance();

            pakiraGenerator.CertaintyScore = 1.0;

            TrainData trainData = new TrainData();

            trainData = trainData.AddSample(ImmutableList.CreateRange(new double[] { 2, 90 }), 42);
            trainData = trainData.AddSample(ImmutableList.CreateRange(new double[] { 250, 140 }), 54);
            trainData = trainData.AddSample(ImmutableList.CreateRange(new double[] { 200, 100 }), 42);

            PakiraDecisionTreeModel pakiraDecisionTreeModel = new PakiraDecisionTreeModel(trainData.Samples[0]);

            pakiraDecisionTreeModel = pakiraGenerator.Generate(pakiraDecisionTreeModel, trainData);

            pakiraDecisionTreeModel.Tree.Root.ShouldNotBeNull();

            pakiraDecisionTreeModel.PredictNode(trainData.Samples[0]).Value.ShouldBe(trainData.Labels[0]);
            pakiraDecisionTreeModel.PredictNode(trainData.Samples[1]).Value.ShouldBe(trainData.Labels[1]);
            pakiraDecisionTreeModel.PredictNode(trainData.Samples[2]).Value.ShouldBe(trainData.Labels[2]);

            pakiraDecisionTreeModel.PredictNode(new SabotenCache(trainData.Samples[0])).PakiraLeaf.Value.ShouldBe(trainData.Labels[0]);
            pakiraDecisionTreeModel.PredictNode(new SabotenCache(trainData.Samples[1])).PakiraLeaf.Value.ShouldBe(trainData.Labels[1]);
            pakiraDecisionTreeModel.PredictNode(new SabotenCache(trainData.Samples[2])).PakiraLeaf.Value.ShouldBe(trainData.Labels[2]);
        }
Пример #4
0
        public void MinimumSampleCount()
        {
            PakiraDecisionTreeGenerator pakiraGenerator = PakiraGeneratorTests.CreatePakiraGeneratorInstance();
            TrainData trainData = new TrainData();

            trainData = trainData.AddSample(ImmutableList.CreateRange(new double[] { 2, 3 }), 42);
            trainData = trainData.AddSample(ImmutableList.CreateRange(new double[] { 20, 140 }), 54);
            trainData = trainData.AddSample(ImmutableList.CreateRange(new double[] { 33, 200 }), 42);

            PakiraDecisionTreeModel pakiraDecisionTreeModel = new PakiraDecisionTreeModel(trainData.Samples[0]);

            pakiraDecisionTreeModel = pakiraGenerator.Generate(pakiraDecisionTreeModel, trainData);

            pakiraDecisionTreeModel.Tree.Root.ShouldNotBeNull();

            pakiraDecisionTreeModel.PredictNode(trainData.Samples[0]).Value.ShouldBe(trainData.Labels[0]);
            pakiraDecisionTreeModel.PredictNode(trainData.Samples[1]).Value.ShouldBe(trainData.Labels[1]);
            pakiraDecisionTreeModel.PredictNode(trainData.Samples[2]).Value.ShouldBe(trainData.Labels[2]);
        }
Пример #5
0
 public void Constructor()
 {
     PakiraDecisionTreeGenerator pakiraGenerator = PakiraGeneratorTests.CreatePakiraGeneratorInstance();
 }