/// <summary> /// classifies an arbitrary example using a built tree. /// /// THE TREE MUST BE BUILT BEFORE CALLING THIS METHOD! /// </summary> public ClassifyOutput Classify(Example example) { TreeNode currentNode = root; double counts = 0; double randomizedCounts = 0; // while we aren't at a leaf node in the tree... while (!currentNode.terminal) { counts++; // look through the list of possible values that current node's // splitting attribute can take on. bool foundChild = false; foreach (var child in currentNode.children) { if (child.value.Equals(example.attributes[currentNode.attribute])) { foundChild = true; currentNode = child; break; } } if (!foundChild) { randomizedCounts++; Console.WriteLine("Choosing random path..."); Random r = new Random(); currentNode = currentNode.children[r.Next(currentNode.children.Count)]; } } ClassifyOutput output; return(output = new ClassifyOutput(currentNode.classification, randomizedCounts / counts)); // return currentNode.classification; }