Esempio n. 1
0
File: ID3.cs Progetto: gitzfibbon/ml
        public ID3Node Train(Instances S, double confidenceLevel, int maxDepth = 0)
        {
            int targetAttributeIndex = S.numAttributes() - 1;

            // Store the attribute indexes in a list. They will get removed as we split on attributes.
            List <int> attributeIndexes = new List <int>();

            for (int i = 0; i < S.numAttributes() - 1; i++)
            {
                attributeIndexes.Add(i);
            }

            this.RootNode       = new ID3Node();
            this.RootNode.Depth = 1;

            this.TrainRecursive(this.RootNode, S, targetAttributeIndex, attributeIndexes, confidenceLevel, maxDepth);

            if (Log.NodeOn == true)
            {
                ID3Node.DFS(this.RootNode, S);
            }

            Log.LogNode("Number of Nodes is {0}", ID3Node.NodeCount(this.RootNode));
            Log.LogNode("Max Tree Depth including leaves is {0}", ID3Node.MaxDepth(this.RootNode));

            return(this.RootNode);
        }
Esempio n. 2
0
        public static void DFS(ID3Node root, Instances instances)
        {
            ID3Node.Print(root, instances);

            if (root.IsLeaf)
            {
                return;
            }

            for (int i = 0; i < root.ChildNodes.Count(); i++)
            {
                ID3Node.DFS(root.ChildNodes[i], instances);
            }
        }