static void Main(string[] args) { Attribute soft_skills = new Attribute("soft_skills", new string[] { "Poor", "Avg", "Good" }); Attribute time_management = new Attribute("time_management", new string[] { "Developed", "Enhanced", "Strengthened" }); Attribute problem_solving = new Attribute("problem_solving", new string[] { "Developed", "low" }); Attribute decision_making = new Attribute("decision_making", new string[] { "yes", "no" }); Attribute[] attributes = new Attribute[] { soft_skills, time_management, problem_solving, decision_making }; DataTable samples = getDataTable(); j48classify j48 = new j48classify(); TreeNode root = j48.mountTree(samples, "result", attributes); printNode(root, ""); }
private TreeNode internalMountTree(DataTable samples, string targetAttribute, Attribute[] attributes) { if (allSamplesPositives(samples, targetAttribute) == "c1") { return(new TreeNode(new Attribute("c1"))); } if (allSamplesNegatives(samples, targetAttribute) == "c1") { return(new TreeNode(new Attribute("c2"))); } if (attributes.Length == 0) { return(new TreeNode(new Attribute(getMostCommonValue(samples, targetAttribute)))); } mTotal = samples.Rows.Count; mTargetAttribute = targetAttribute; mTotalPositives = countTotalPositives(samples); mEntropySet = calcEntropy(mTotalPositives, mTotal - mTotalPositives); Attribute bestAttribute = getBestAttribute(samples, attributes); TreeNode root = new TreeNode(bestAttribute); DataTable aSample = samples.Clone(); foreach (string value in bestAttribute.values) { aSample.Rows.Clear(); DataRow[] rows = samples.Select(bestAttribute.AttributeName + " = " + "'" + value + "'"); foreach (DataRow row in rows) { aSample.Rows.Add(row.ItemArray); } ArrayList aAttributes = new ArrayList(attributes.Length - 1); for (int i = 0; i < attributes.Length; i++) { if (attributes[i].AttributeName != bestAttribute.AttributeName) { aAttributes.Add(attributes[i]); } } if (aSample.Rows.Count == 0) { return(new TreeNode(new Attribute(getMostCommonValue(aSample, targetAttribute)))); } else { j48classify dc3 = new j48classify(); TreeNode ChildNode = dc3.mountTree(aSample, targetAttribute, (Attribute[])aAttributes.ToArray(typeof(Attribute))); root.AddTreeNode(ChildNode, value); } } return(root); }