Advertisement
cesarsouza

Nursery tree creation

Jan 10th, 2013
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. string[] lines = Resources.nursery.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
  2.  
  3. DataTable table = new DataTable("Nursery");
  4. table.Columns.Add("parents", "has_nurs", "form", "children",
  5.     "housing", "finance", "social", "health", "output");
  6.  
  7. foreach (var line in lines)
  8.     table.Rows.Add(line.Split(','));
  9.  
  10.  
  11. // Create learning data
  12. Codification codebook = new Codification(table);
  13. DataTable symbols = codebook.Apply(table);
  14.  
  15. double[][] inputs = symbols.ToArray("parents", "has_nurs", "form", "children", "housing", "finance", "social", "health");
  16. int[] outputs = symbols.ToIntArray("output").GetColumn(0);
  17.  
  18.  
  19. // Create tree
  20. DecisionVariable[] attributes =
  21. {
  22.     new DecisionVariable("parents",  3),
  23.     new DecisionVariable("has_nurs", 5),
  24.     new DecisionVariable("form",     4),
  25.     new DecisionVariable("children", 4),
  26.     new DecisionVariable("housing",  3),
  27.     new DecisionVariable("finance",  2),
  28.     new DecisionVariable("social",   3),
  29.     new DecisionVariable("health",   3),
  30. };
  31.  
  32. DecisionTree tree = new DecisionTree(attributes, 5);
  33.  
  34. // Create C45 and learn the tree
  35. C45Learning c45 = new C45Learning(tree);
  36. double error = c45.Run(inputs, outputs);
  37.  
  38. var exp = tree.ToExpression();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement