LogLossMetric<T>

Models & Types · AiDotNet.Evaluation.Metrics.Classification

Computes Log Loss (Cross-Entropy Loss): a probabilistic measure that penalizes confident wrong predictions.

Implements: IProbabilisticClassificationMetric<T>

For Beginners

Log loss measures how well predicted probabilities match actual outcomes. Unlike accuracy which just checks if the prediction is correct, log loss considers the confidence:

  • Predicting 0.99 when correct: Low loss (good)
  • Predicting 0.51 when correct: Higher loss (less confident)
  • Predicting 0.99 when wrong: Very high loss (confidently wrong = bad)

How It Works

For binary classification: Log Loss = -1/N * Σ[y*log(p) + (1-y)*log(1-p)]

For multi-class: Log Loss = -1/N * Σ Σ y_ik * log(p_ik)

Interpretation:

  • Log Loss = 0: Perfect predictions with complete confidence
  • Lower is better
  • Log Loss approaches infinity for confidently wrong predictions

Use cases: Essential for evaluating probabilistic classifiers, probability calibration, and whenever predicted probabilities (not just class labels) matter.

Constructors

Constructor Summary
LogLossMetric(double epsilon) Initializes a new Log Loss metric.

Properties

Property Summary
MetricDirection Direction { get; }
T MaxValue { get; }
T MinValue { get; }
bool RequiresProbabilities { get; }
bool SupportsMultiClass { get; }
string Category { get; }
string Description { get; }
string Name { get; }

Methods

Method Summary
MetricWithCI<T> ComputeWithCI(ReadOnlySpan<T> probabilities, ReadOnlySpan<T> actuals, int numClasses, ConfidenceIntervalMethod ciMethod, double confidenceLevel, int bootstrapSamples, int? randomSeed)
T Compute(ReadOnlySpan<T> probabilities, ReadOnlySpan<T> actuals, int numClasses)