/// <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."); }
/// <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)); }