Esempio n. 1
0
        public void Build(weka.core.Instances instances)
        {
            WekaUtils.DebugAssert(instances.numClasses() == 3, "instance's numClasses should be 3.");
            for (int i = 0; i < m_counts.Length; i++)
            {
                m_counts[i] = 0;
            }

            double c = m_tp / m_sl;

            foreach (weka.core.Instance instance in instances)
            {
                int v = (int)instance.classValue();
                if (v == 2)
                {
                    m_counts[2] += c;
                }
                else if (v == 0)
                {
                    m_counts[0]++;
                }
                else
                {
                    m_counts[1]++;
                }
            }
        }
Esempio n. 2
0
        ///
        ///             <summary> * Generates the classifier.
        ///             * </summary>
        ///             * <param name="instances"> set of instances serving as training data  </param>
        ///             * <exception cref="Exception"> if the classifier has not been generated successfully </exception>
        ///
        public override void buildClassifier(Instances instances)
        {
            // can classifier handle the data?
            getCapabilities().testWithFail(instances);

            // remove instances with missing class
            instances = new Instances(instances);
            instances.deleteWithMissingClass();

            double sumOfWeights = 0;

            WekaUtils.DebugAssert(instances.numClasses() == 3, "instance's numClasses should be 3.");
            m_counts       = new double[instances.numClasses()];
            m_normalCounts = new double[instances.numClasses()];
            for (int i = 0; i < m_counts.Length; i++)
            {
                m_counts[i]       = 0;
                m_normalCounts[i] = 0;
            }

            double c = m_tp / m_sl;

            foreach (Instance instance in instances)
            {
                int v = (int)instance.classValue();
                if (v == 2)
                {
                    m_counts[v]  += instance.weight() * c;
                    sumOfWeights += instance.weight() * c;
                }
                else
                {
                    m_counts[v]  += instance.weight();
                    sumOfWeights += instance.weight();
                }
            }

            double start = 0;

            for (int i = 0; i < m_counts.Length; ++i)
            {
                m_normalCounts[i] = (double)m_counts[i] / sumOfWeights + start;
                start             = m_normalCounts[i];
            }
        }