Ejemplo n.º 1
0
        /// <summary>
        /// Decide whether to follow the true-branch or the false-branch.
        /// Compare the feature / value stored in the node,
        /// to the example we're considering.
        /// </summary>
        private static DecisionNode Classify(Dictionary <string, string> dataRow, DecisionNode node)
        {
            if (node.IsLeaf())
            {
                return(node);
            }

            if (node.Question.IsMatch(dataRow))
            {
                return(Classify(dataRow, node.TrueBranch));
            }
            else
            {
                return(Classify(dataRow, node.FalseBranch));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// World's most elegant tree printing function.
        /// </summary>
        public static void PrintTree(DecisionNode node, string spacing = "")
        {
            if (node.IsLeaf())
            {
                DebugLog(spacing + node, ConsoleColor.Green);
                return;
            }

            DebugLog(spacing + node.Question);

            DebugLog(spacing + "--> True:");
            PrintTree(node.TrueBranch, spacing + "  ");

            DebugLog(spacing + "--> False:");
            PrintTree(node.FalseBranch, spacing + "  ");
        }