Accord.Statistics.Analysis.ConfusionMatrix.ToString C# (CSharp) Method

ToString() public method

Returns a System.String representing this confusion matrix.
public ToString ( ) : string
return string
        public override string ToString()
        {
            return String.Format(System.Globalization.CultureInfo.CurrentCulture,
                "TP:{0} FP:{2}, FN:{3} TN:{1}",
                truePositives, trueNegatives, falsePositives, falseNegatives);
        }

Usage Example

Example #1
0
        /// <summary>
        /// Validate than Accord.Net DecisionTree or MulticlassSupportVectorMachine class
        /// </summary>
        /// <param name="test">The test dataset</param>
        /// <param name="obj">The Accord.Net DecisionTree or MulticlassSupportVectorMachine object</param>
        public static void Validate(DataTable test, object obj)
        {
            List<int> expected = new List<int>();
            List<int> predicted = new List<int>();

            foreach (DataRow row in test.Rows)
            {
                double gender = 1;
                if (string.Compare((string)row["Gender"], "F", true, CultureInfo.CurrentCulture) == 0)
                {
                    gender = 0;
                }

                double[] testQuery = new double[]
                                                 {
                                                    gender, Convert.ToDouble(row["YearOfBirth"], CultureInfo.CurrentCulture), Convert.ToDouble(row["SmokingEffectiveYear"], CultureInfo.CurrentCulture), Convert.ToDouble(row["NISTcode"], CultureInfo.CurrentCulture),
                                                    Convert.ToDouble(row["Height"], CultureInfo.CurrentCulture), Convert.ToDouble(row["Weight"], CultureInfo.CurrentCulture), Convert.ToDouble(row["BMI"], CultureInfo.CurrentCulture),
                                                    Convert.ToDouble(row["SystolicBP"], CultureInfo.CurrentCulture), Convert.ToDouble(row["DiastolicBP"], CultureInfo.CurrentCulture), Convert.ToDouble(row["RespiratoryRate"], CultureInfo.CurrentCulture),
                                                    Convert.ToDouble(row["Temperature"], CultureInfo.CurrentCulture)
                                                 };

                int output = -1;
                if (obj is DecisionTree)
                {
                    output = ((DecisionTree)obj).Compute(testQuery);
                }
                else if (obj is MulticlassSupportVectorMachine)
                {
                    output = ((MulticlassSupportVectorMachine)obj).Compute(testQuery);
                }
                else
                {
                    throw new ArgumentException("Unknown algorithm for validation.");
                }

                expected.Add(Convert.ToInt32(row["DMIndicator"], CultureInfo.CurrentCulture));
                predicted.Add(output);
            }

            var confusionMatrix = new ConfusionMatrix(predicted.ToArray(), expected.ToArray());
            Logger.Info("The following is the confusion matrix (aka truth table).  Look for TP (true positive), FP (false positive), etc...");
            Logger.Info("Accuracy :" + confusionMatrix.ToString());
            Logger.Info("Hit Enter to continue....");
            Console.ReadLine();
        }