Esempio n. 1
0
        /// <summary>
        /// Gets the metric value for the given confusion matrix.
        /// </summary>
        /// <param name="matrix">Confusion matrix.</param>
        /// <param name="metric">Metric to compute.</param>
        /// <returns>Metric value.</returns>
        internal static double GetMetric(this ConfusionMatrix matrix, string metric)
        {
            if (metric == null)
            {
                return(matrix.F1());
            }
            else if (metric == "precision")
            {
                return(matrix.Precision());
            }
            else if (metric == "recall")
            {
                return(matrix.Recall());
            }
            else if (metric.StartsWith("f", StringComparison.OrdinalIgnoreCase) && double.TryParse(metric.Substring(1), out var beta))
            {
                return(matrix.FScore(beta));
            }

            throw new ArgumentOutOfRangeException(nameof(metric), $"Invalid metric value provided.");
        }
Esempio n. 2
0
 /// <summary>
 /// Calculates the precision from a confusion matrix
 /// </summary>
 /// <param name="cm">confusion matrix metrics</param>
 /// <returns>The precision result</returns>
 private static double Precision(this ConfusionMatrix cm)
 {
     return(Divide(cm.TruePositive, cm.TruePositive + cm.FalsePositive));
 }
Esempio n. 3
0
 /// <summary>
 ///  Calculates the recall from a confusion matrix
 /// </summary>
 /// <param name="cm"> confusin matrix metrics</param>
 /// <returns> The recall result</returns>
 private static double Recall(this ConfusionMatrix cm)
 {
     return(Divide(cm.TruePositive, cm.TruePositive + cm.FalseNegative));
 }
Esempio n. 4
0
 /// <summary>
 /// Calculates total count for the confusion matrix.
 /// </summary>
 /// <param name="matrix">Confusion matrix.</param>
 /// <returns>Total count.</returns>
 internal static int Total(this ConfusionMatrix matrix)
 {
     return(matrix.TruePositive + matrix.TrueNegative + matrix.FalsePositive + matrix.FalseNegative);
 }
Esempio n. 5
0
 /// <summary>
 /// Calculates the F<sub>1</sub> score from a confusion matrix.
 /// </summary>
 /// <param name="matrix">Confusion matrix.</param>
 /// <returns>F<sub>1</sub> score.</returns>
 internal static double F1(this ConfusionMatrix matrix)
 {
     return(matrix.FScore(1));
 }
Esempio n. 6
0
 /// <summary>
 /// Calculates the recall from a confusion matrix.
 /// </summary>
 /// <param name="matrix">Confusion matrix.</param>
 /// <returns>Recall value.</returns>
 internal static double Recall(this ConfusionMatrix matrix)
 {
     return(Divide(matrix.TruePositive, matrix.TruePositive + matrix.FalseNegative));
 }
Esempio n. 7
0
 /// <summary>
 /// Calculates the precision from a confusion matrix.
 /// </summary>
 /// <param name="matrix">Confusion matrix.</param>
 /// <returns>Precision value.</returns>
 internal static double Precision(this ConfusionMatrix matrix)
 {
     return(Divide(matrix.TruePositive, matrix.TruePositive + matrix.FalsePositive));
 }