CreateMitchellExample() 공개 정적인 메소드

public static CreateMitchellExample ( Accord.MachineLearning.DecisionTrees.DecisionTree &tree, int &inputs, int &outputs ) : void
tree Accord.MachineLearning.DecisionTrees.DecisionTree
inputs int
outputs int
리턴 void
예제 #1
0
        public void EnumerateTest()
        {
            DecisionTree tree;

            int[][] inputs;
            int[]   outputs;

            ID3LearningTest.CreateMitchellExample(out tree, out inputs, out outputs);


            DecisionNode[] expected =
            {
                tree.Root,
                tree.Root.Branches[0],             // Outlook = 0
                tree.Root.Branches[0].Branches[0], // Humidity = 0
                tree.Root.Branches[0].Branches[1], // Humidity = 1
                tree.Root.Branches[1],             // Outlook = 1
                tree.Root.Branches[2],             // Outlook = 2
                tree.Root.Branches[2].Branches[0], // Wind = 0
                tree.Root.Branches[2].Branches[1], // Wind = 1
            };

            int i = 0;

            foreach (var node in tree)
            {
                Assert.AreEqual(expected[i++], node);
            }

            Assert.AreEqual(expected.Length, i);
        }
예제 #2
0
        public void unknown_values_test()
        {
            // https://github.com/accord-net/framework/issues/689

            DecisionTree tree;

            int[][] inputs;
            int[]   outputs;

            ID3LearningTest.CreateMitchellExample(out tree, out inputs, out outputs);

            int a = tree.Decide(new[] { 42, Double.NaN, 52, 21 });
            int b = tree.Decide(new[] { 42, 3, 52, 21 });

            Assert.AreEqual(0, a);
            Assert.AreEqual(0, b);
        }
        public void WriteTest()
        {
            DecisionTree tree;

            int[][] inputs;
            int[]   outputs;
            ID3LearningTest.CreateMitchellExample(out tree, out inputs, out outputs);

            var csc        = new CSharpCodeProvider();
            var parameters = new CompilerParameters(new[] { "System.dll", "mscorlib.dll" })
            {
                GenerateInMemory = true
            };

            var compilerResult = csc.CompileAssemblyFromSource(parameters, tree.ToCode("AccordDecisionTree"));

            Assert.That(compilerResult.Errors.HasErrors, Is.False, ToString(compilerResult.Errors));
        }
예제 #4
0
        public void DeserializationTest1()
        {
            MemoryStream stream = new MemoryStream(Properties.Resources.tree);

            DecisionTree tree = Serializer.Load <DecisionTree>(stream);

            Assert.AreEqual(4, tree.InputCount);
            Assert.AreEqual(2, tree.OutputClasses);
            Assert.IsNotNull(tree.Root);

            DecisionTree newtree;

            int[][] inputs;
            int[]   outputs;

            ID3LearningTest.CreateMitchellExample(out newtree, out inputs, out outputs);


            for (int i = 0; i < inputs.Length; i++)
            {
                int y = tree.Compute(inputs[i].ToDouble());
                Assert.AreEqual(outputs[i], y);
            }

            DecisionNode[] expected =
            {
                tree.Root,
                tree.Root.Branches[0],             // Outlook = 0
                tree.Root.Branches[1],             // Outlook = 1
                tree.Root.Branches[2],             // Outlook = 2
                tree.Root.Branches[0].Branches[0], // Humidity = 0
                tree.Root.Branches[0].Branches[1], // Humidity = 1
                tree.Root.Branches[2].Branches[0], // Wind = 0
                tree.Root.Branches[2].Branches[1], // Wind = 1
            };

            int c = 0;

            foreach (var node in tree.Traverse(DecisionTreeTraversal.BreadthFirst))
            {
                Assert.AreEqual(expected[c++], node);
            }
            Assert.AreEqual(expected.Length, c);
        }
예제 #5
0
        public void ComputeTest()
        {
            DecisionTree tree;

            int[][] inputs;
            int[]   outputs;

            ID3LearningTest.CreateMitchellExample(out tree, out inputs, out outputs);

            Assert.AreEqual(4, tree.InputCount);
            Assert.AreEqual(2, tree.OutputClasses);


            for (int i = 0; i < inputs.Length; i++)
            {
                int y = tree.Compute(inputs[i].ToDouble());
                Assert.AreEqual(outputs[i], y);
            }
        }
예제 #6
0
        public void CreateTest()
        {
            DecisionTree tree;

            int[][] inputs;
            int[]   outputs;

            ID3LearningTest.CreateMitchellExample(out tree, out inputs, out outputs);

            // Convert to an expression tree
            var expression = tree.ToExpression();

            // Compiles the expression
            var func = expression.Compile();


            for (int i = 0; i < inputs.Length; i++)
            {
                int y = func(inputs[i].ToDouble());
                Assert.AreEqual(outputs[i], y);
            }
        }
예제 #7
0
        public void TraverseTest()
        {
            DecisionTree tree;

            int[][] inputs;
            int[]   outputs;

            ID3LearningTest.CreateMitchellExample(out tree, out inputs, out outputs);


            {
                DecisionNode[] expected =
                {
                    tree.Root,
                    tree.Root.Branches[0],             // Outlook = 0
                    tree.Root.Branches[1],             // Outlook = 1
                    tree.Root.Branches[2],             // Outlook = 2
                    tree.Root.Branches[0].Branches[0], // Humidity = 0
                    tree.Root.Branches[0].Branches[1], // Humidity = 1
                    tree.Root.Branches[2].Branches[0], // Wind = 0
                    tree.Root.Branches[2].Branches[1], // Wind = 1
                };

                int i = 0;
                foreach (var node in tree.Traverse(DecisionTreeTraversal.BreadthFirst))
                {
                    Assert.AreEqual(expected[i++], node);
                }
                Assert.AreEqual(expected.Length, i);
            }

            {
                DecisionNode[] expected =
                {
                    tree.Root,
                    tree.Root.Branches[0],             // Outlook = 0
                    tree.Root.Branches[0].Branches[0], // Humidity = 0
                    tree.Root.Branches[0].Branches[1], // Humidity = 1
                    tree.Root.Branches[1],             // Outlook = 1
                    tree.Root.Branches[2],             // Outlook = 2
                    tree.Root.Branches[2].Branches[0], // Wind = 0
                    tree.Root.Branches[2].Branches[1], // Wind = 1
                };

                int i = 0;
                foreach (var node in tree.Traverse(DecisionTreeTraversal.DepthFirst))
                {
                    Assert.AreEqual(expected[i++], node);
                }
                Assert.AreEqual(expected.Length, i);
            }

            {
                DecisionNode[] expected =
                {
                    tree.Root.Branches[0].Branches[0], // Humidity = 0
                    tree.Root.Branches[0].Branches[1], // Humidity = 1
                    tree.Root.Branches[0],             // Outlook = 0
                    tree.Root.Branches[1],             // Outlook = 1
                    tree.Root.Branches[2].Branches[0], // Wind = 0
                    tree.Root.Branches[2].Branches[1], // Wind = 1
                    tree.Root.Branches[2],             // Outlook = 2
                    tree.Root,
                };

                int i = 0;
                foreach (var node in tree.Traverse(DecisionTreeTraversal.PostOrder))
                {
                    Assert.AreEqual(expected[i++], node);
                }
                Assert.AreEqual(expected.Length, i);
            }
        }