Esempio n. 1
0
        public Tuple <string, double> findBestSplitNumerical()
        {
            sortTable();
            ClassCounter allTable   = new ClassCounter(this);
            string       splitValue = attributes[0].getValueAsString();
            double       bestGini   = 999;
            double       currentGini;
            int          j = 0;

            for (int i = 0; i < attributes.Count - 1; i++)
            {
                if (!attributes[i].getValueAsString().Equals(attributes[i + 1].getValueAsString()))
                {
                    var tuple = splitTableNumerical(i + 1);
                    currentGini = rateSplit(tuple.Item1, tuple.Item2, allTable);
                    if (currentGini < bestGini)
                    {
                        bestGini   = currentGini;
                        splitValue = attributes[i].getValueAsString();
                        j          = i;
                    }
                }
            }

            bestGini = (attributes[j].getValueAsDouble() + attributes[j + 1].getValueAsDouble()) / 2;
            Tuple <string, double> toReturn = new Tuple <string, double>(splitValue, bestGini);

            return(toReturn);
        }
Esempio n. 2
0
        private double rateSplit(AttributeTable first, AttributeTable second, ClassCounter allTable)
        {
            ClassCounter firstCounter  = new ClassCounter(first);
            ClassCounter secondCounter = new ClassCounter(second);

            return(firstCounter.calculateGiniSplit(allTable) + secondCounter.calculateGiniSplit(allTable));
        }
Esempio n. 3
0
        public double calculateGiniSplit(ClassCounter globalTable)
        {
            double nominator   = (double)counters.Sum();
            double denominator = (double)globalTable.counters.Sum();

            return(calculateGini() * nominator / denominator);
        }