Example #1
0
 private bool searchTree(DNode n, DataRow row)
 {
     if(n.classification != null)
     {return row.checkClass(n.classification);}
     else
     {
         string a = row.getAttribute(n.attribute);
         for(uint x = 0; x < n.children.Length; x++)
         {
             if(n.children[x].path.Equals(a))
             { return searchTree(n.children[x],row);}
         }
     }
     //Console.WriteLine("Am I here");
     return false; //should never get here
 }
Example #2
0
        public DNode(DataSet classify, ref bool[] marked, string path)
        {
            //Console.WriteLine(markedString(marked));
            classification = null; //only gets set on leaf node
            attr_assigned = false; //unassigned
            this.path = path;

            //if the tree is perfectly classified (entropy == 0)
            // or if we're out of attributes, return the most occuring one
            if(classify.entropy == 0 || allMarked(ref marked))
            { classification = classify.getMostOccuringClassification();}
            else
            {
                attribute = classify.bestGain(marked);
                attr_assigned = true;
                children = new DNode[classify.getAttributes(attribute).Length];
                //Console.WriteLine("Attrib: " + attribute + " Children: " + classify.getAttributes(attribute).Length);
                for(uint x=0; x < children.Length; x++)
                {
                    marked[attribute] = true;
                    string tmp = classify.getAttributes(attribute)[x];
                    children[x] = new DNode(classify.partitionData(attribute,tmp),ref marked,tmp);
                }
            }
        }
Example #3
0
 public DTree(DataSet classify)
 {
     bool[] marked = new bool[classify.numAttributes()];
     root = new DNode(classify,ref marked, "");
 }