createNurseryExample() public static method

public static createNurseryExample ( double &inputs, int &outputs, int first ) : Accord.MachineLearning.DecisionTrees.DecisionTree
inputs double
outputs int
first int
return Accord.MachineLearning.DecisionTrees.DecisionTree
        public void RunTest3()
        {
            Accord.Math.Random.Generator.Seed = 0;

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

            int          training = 6000;
            DecisionTree tree     = ReducedErrorPruningTest.createNurseryExample(out inputs, out outputs, training);

            double[] actual = new double[10];

            for (int i = 0; i < actual.Length; i++)
            {
                int nodeCount2;
                repeat(inputs, outputs, tree, training, i * 0.1, out nodeCount2);

                actual[i] = nodeCount2;
            }

            double[] expected = { 447, 424, 410, 402, 376, 362, 354, 348, 336, 322 };

            for (int i = 0; i < actual.Length; i++)
            {
                Assert.AreEqual(expected[i], actual[i]);
            }
        }
Beispiel #2
0
        public void RunTest3()
        {
            double[][] inputs;
            int[]      outputs;

            int          training = 6000;
            DecisionTree tree     = ReducedErrorPruningTest.createNurseryExample(out inputs, out outputs, training);

            double[] actual = new double[10];

            for (int i = 0; i < actual.Length; i++)
            {
                int nodeCount2;
                repeat(inputs, outputs, tree, training, i * 0.1, out nodeCount2);

                actual[i] = nodeCount2;
            }

            double[] expected = { 447, 193, 145, 140, 124, 117, 109, 103, 95, 87 };

            for (int i = 0; i < actual.Length; i++)
            {
                Assert.AreEqual(expected[i], actual[i]);
            }
        }
        public void RunTest()
        {
            Accord.Math.Random.Generator.Seed = 0;

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

            int          trainingSamplesCount = 6000;
            DecisionTree tree = ReducedErrorPruningTest.createNurseryExample(out inputs, out outputs, trainingSamplesCount);

            int nodeCount = 0;

            foreach (var node in tree)
            {
                nodeCount++;
            }

            var pruningInputs       = inputs.Submatrix(trainingSamplesCount, inputs.Length - 1);
            var pruningOutputs      = outputs.Submatrix(trainingSamplesCount, inputs.Length - 1);
            ErrorBasedPruning prune = new ErrorBasedPruning(tree, pruningInputs, pruningOutputs);

            prune.Threshold = 0.1;

            double lastError, error = Double.PositiveInfinity;

            do
            {
                lastError = error;
                error     = prune.Run();
            } while (error < lastError);

            int nodeCount2 = 0;

            foreach (var node in tree)
            {
                nodeCount2++;
            }

            Assert.AreEqual(0.28922413793103446, error, 5e-4);
            Assert.AreEqual(447, nodeCount);
            Assert.AreEqual(424, nodeCount2);
        }
        public void RunTest()
        {
            double[][] inputs;
            int[]      outputs;

            int          training = 6000;
            DecisionTree tree     = ReducedErrorPruningTest.createNurseryExample(out inputs, out outputs, training);

            int nodeCount = 0;

            foreach (var node in tree)
            {
                nodeCount++;
            }

            var pruningInputs       = inputs.Submatrix(training, inputs.Length - 1);
            var pruningOutputs      = outputs.Submatrix(training, inputs.Length - 1);
            ErrorBasedPruning prune = new ErrorBasedPruning(tree, pruningInputs, pruningOutputs);

            prune.Threshold = 0.1;

            double lastError, error = Double.PositiveInfinity;

            do
            {
                lastError = error;
                error     = prune.Run();
            } while (error < lastError);

            int nodeCount2 = 0;

            foreach (var node in tree)
            {
                nodeCount2++;
            }

            Assert.AreEqual(0.25459770114942532, error);
            Assert.AreEqual(447, nodeCount);
            Assert.AreEqual(193, nodeCount2);
        }