Esempio n. 1
0
        static void Main(string[] args)
        {
            Attribute ceu         = new Attribute("ceu", new string[] { "sol", "nublado", "chuva" });
            Attribute temperatura = new Attribute("temperatura", new string[] { "alta", "baixa", "suave" });
            Attribute humidade    = new Attribute("humidade", new string[] { "alta", "normal" });
            Attribute vento       = new Attribute("vento", new string[] { "sim", "nao" });

            Attribute[] attributes = new Attribute[] { ceu, temperatura, humidade, vento };

            DataTable samples = getDataTable();

            DecisionTreeID3 id3  = new DecisionTreeID3();
            TreeNode        root = id3.mountTree(samples, "result", attributes);

            printNode(root, "");
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Attribute ceu = new Attribute("ceu", new string[] {"sol", "nublado", "chuva"});
            Attribute temperatura = new Attribute("temperatura", new string[] {"alta", "baixa", "suave"});
            Attribute humidade = new Attribute("humidade", new string[] {"alta", "normal"});
            Attribute vento = new Attribute("vento", new string[] {"sim", "nao"});

            Attribute[] attributes = new Attribute[] {ceu, temperatura, humidade, vento};

            DataTable samples = getDataTable();

            DecisionTreeID3 id3 = new DecisionTreeID3();
            TreeNode root = id3.mountTree(samples, "result", attributes);

            printNode(root, "");
        }
Esempio n. 3
0
        private TreeNode internalMountTree(DataTable samples, string targetAttribute, Attribute[] attributes)
        {
            if (allSamplesPositives(samples, targetAttribute) == true)
                return new TreeNode(new Attribute(true));

            if (allSamplesNegatives(samples, targetAttribute) == true)
                return new TreeNode(new Attribute(false));

            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
                {
                    DecisionTreeID3 dc3 = new DecisionTreeID3();
                    TreeNode ChildNode =  dc3.mountTree(aSample, targetAttribute, (Attribute[])aAttributes.ToArray(typeof(Attribute)));
                    root.AddTreeNode(ChildNode, value);
                }
            }

            return root;
        }
Esempio n. 4
0
        private TreeNode internalMountTree(DataTable samples, string targetAttribute, Attribute[] attributes)
        {
            if (allSamplesPositives(samples, targetAttribute) == true)
            {
                return(new TreeNode(new Attribute(true)));
            }

            if (allSamplesNegatives(samples, targetAttribute) == true)
            {
                return(new TreeNode(new Attribute(false)));
            }

            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
                {
                    DecisionTreeID3 dc3       = new DecisionTreeID3();
                    TreeNode        ChildNode = dc3.mountTree(aSample, targetAttribute, (Attribute[])aAttributes.ToArray(typeof(Attribute)));
                    root.AddTreeNode(ChildNode, value);
                }
            }

            return(root);
        }