Exemplo n.º 1
0
        /*This function is used to print the decision tree*/
        public static void printNode(TreeNode root, string tabs)
        {
            if (root.totalCountOfChilds == 1)
            {
                Console.Write(root.attribute);
                Console.Write(Environment.NewLine);
            }
            else
            {

                Console.Write(tabs + "|" + root.attribute);

            }
            if (root.attribute.values != null)
            {
                for (int i = 0; i < root.attribute.values.Length; i++)
                {

                    if (i > 0)
                    {
                        Console.Write(tabs + "|" + root.attribute + "=" + root.attribute.values[i] + ":");
                    }
                    else
                    {
                        Console.Write("=" + root.attribute.values[i] + ":");
                    }
                    TreeNode childNode = root.getBranchChild(root.attribute.values[i]);
                    if (childNode.totalCountOfChilds > 1)
                    {
                        Console.Write(Environment.NewLine);
                        printNode(childNode, "| \t" + tabs);
                    }
                    else
                    {
                        printNode(childNode, "\t" + tabs);
                    }

                }

            }
        }
Exemplo n.º 2
0
        public static void Traverse(TreeNode node, DataRow dt, ref string val)
        {
            string currentval = string.Empty;

            if (node.attribute.values != null)
            {
                currentval = dt[node.attribute.ToString()].ToString();
                bool result = CheckForMissingValue(node.attribute.values, currentval);
                if (result == true)
                {
                    if (node.attribute.postives >= node.attribute.negatives)
                    {
                        val = "1";
                        return;
                    }
                    else if (node.attribute.postives < node.attribute.negatives)
                    {
                        val = "0";
                        return;
                    }
                }
                else
                {

                    for (int i = 0; i < node.attribute.values.Length; i++)
                    {
                        currentval = dt[node.attribute.ToString()].ToString();
                        if (currentval == node.attribute.values[i])
                        {
                            TreeNode childNode = node.getBranchChild(node.attribute.values[i]);

                            Traverse(childNode, dt, ref val);

                        }
                    }

                }
            }

            else
            {

                val = node.attribute.aLabel.ToString();
                return;
            }
        }