private void DecisionNodeToNodeClass(DecisionNode decisionNode, Node currentNode) { if (!decisionNode.IsRoot) { string comparation = decisionNode.ToString(); string[] aux = comparation.Split(' '); currentNode.parent.value = int.Parse(aux[0]) + 1; int column = int.Parse(aux[0]) + 1; if (column == 1) { string comparator = Math.Floor(double.Parse(aux[2])) == 0 ? "30" : "60"; currentNode.message = Patient.getNamesColums(column) + " " + aux[1] + " " + comparator; } else if (column == 2) { string comparator = aux[1].Contains(">") ? "M" : "F"; currentNode.message = Patient.getNamesColums(column) + " " + comparator; } else if (column == 8) { currentNode.message = "Value " + aux[1] + " " + Math.Floor(double.Parse(aux[2])); } else if (column == 6) { string comparator = "120 mg/dl"; currentNode.message = Patient.getNamesColums(column) + " " + aux[1] + " " + comparator; } else { currentNode.message = Patient.getNamesColums(column) + " " + aux[1] + " " + Math.Floor(double.Parse(aux[2])); } } else { currentNode.height = 1; } currentNode.answer = decisionNode.Output; currentNode.nodes = new Node[decisionNode.Branches.Count]; int distX = 2 * Visualization.SIZE + 10 * currentNode.nodes.Length; currentNode.distX = distX; int i = 0; foreach (DecisionNode childNode in decisionNode.Branches) { Node newNode = new Node(); currentNode.nodes[i] = newNode; newNode.parent = currentNode; newNode.height = newNode.parent.height + 1; newNode.posY = newNode.parent.posY + Visualization.DIST_Y; DecisionNodeToNodeClass(childNode, newNode); i++; } if (decisionNode.IsLeaf) { currentNode.value = null; currentNode.answer = currentNode.answer == null ? -1 : currentNode.answer; } }
private TreeNode convert(DecisionNode node) { TreeNode treeNode = (codebook == null) ? new TreeNode(node.ToString()) : new TreeNode(node.ToString(codebook)); if (!node.IsLeaf) { foreach (var child in node.Branches) { treeNode.Nodes.Add(convert(child)); } return(treeNode); } if (codebook == null || !node.Output.HasValue) { treeNode.Nodes.Add(new TreeNode(node.Output.ToString())); return(treeNode); } int index = node.Parent.Branches.AttributeIndex; var attrib = treeSource.Attributes[index]; if (attrib.Nature != DecisionVariableKind.Discrete) { treeNode.Nodes.Add(new TreeNode(node.Output.ToString())); return(treeNode); } string value = codebook.Translate(attrib.Name, node.Output.Value); treeNode.Nodes.Add(new TreeNode(value)); return(treeNode); }
// Regress tree private TreeNode convert(DecisionNode node) { string attributeName; string attributeValue; TreeNode treeNode; // Add root if (node.IsRoot) { treeNode = new TreeNode(node.ToString()); } else { attributeName = node.Owner.Attributes[node.Parent.Branches.AttributeIndex].Name; attributeValue = this.codification.Translate(attributeName, Convert.ToInt32(node.Value)); // Create new treeNode to TreeView treeNode = new TreeNode(attributeName + "=" + attributeValue); } // If node is leaf if (node.IsLeaf) { // If node has value add classifier value if (node.Output.HasValue) { attributeName = TableMetaData.ClassAttribute; attributeValue = this.codification.Translate(attributeName, Convert.ToInt32(node.Output)); treeNode.Nodes.Add(new TreeNode(attributeValue)); } // Add "" else { treeNode.Nodes.Add(new TreeNode(node.Output.ToString())); } } // Regress all child nodes else { foreach (var child in node.Branches) { treeNode.Nodes.Add(convert(child)); } } return(treeNode); }
public static void PrintTree(DecisionNode node, String indent, bool last) { Console.WriteLine(); string[] spstr = { " == " }; var values = node.ToString().Split(spstr, StringSplitOptions.None); string nodeValue = node.ToString(); if (values.Count() == 2) { nodeValue = values[0] + " == " + codebook.Revert(values[0].Trim(), Int32.Parse(values[1].Trim())).ToString(); } Console.Write(indent + "+- " + nodeValue); indent += last ? " " : "| "; if (last) { Console.Write(" => " + codebook.Revert("Activity", (int)node.Output)); } for (int i = 0; i < node.Branches.Count; i++) { PrintTree(node.Branches[i], indent, node.Branches[i].IsLeaf); } }
private TreeNode convert(DecisionNode node) { TreeNode treeNode = new TreeNode(node.ToString()); if (node.IsLeaf) { treeNode.Nodes.Add(new TreeNode(node.Output.ToString())); } else { foreach (var child in node.Branches) { treeNode.Nodes.Add(convert(child)); } } return(treeNode); }