コード例 #1
0
        /// <summary>
        /// computes points for given trashold
        /// </summary>
        /// <param name="threshold"></param>
        /// <returns></returns>
        public ConfusionMatrix ComputePoint(double threshold)
        {
            int truePositives = 0;
            int trueNegatives = 0;

            for (int i = 0; i < this.m_expected.Length; i++)
            {
                bool actual    = (this.m_expected[i] == m_dtrueValue);
                bool predicted = (this.m_prediction[i] >= threshold);


                // If the prediction equals the true measured value
                if (predicted == actual)
                {
                    // We have a hit. Now we have to see
                    //  if it was a positive or negative hit
                    if (predicted == true)
                    {
                        truePositives++; // Positive hit
                    }
                    else
                    {
                        trueNegatives++; // Negative hit
                    }
                }
            }

            // The other values can be computed from available variables
            int falsePositives = m_negativeCount - trueNegatives;
            int falseNegatives = m_positiveCount - truePositives;

            var cm = new ConfusionMatrix(
                truePositives: truePositives, falseNegatives: falseNegatives,
                falsePositives: falsePositives, trueNegatives: trueNegatives);

            cm.SetCutOffValue(threshold);

            return(cm);
        }