MatthewsCorrelationCoefficientMetric<T>
Models & Types · AiDotNet.Evaluation.Metrics.Classification
Computes Matthews Correlation Coefficient (MCC): a balanced measure for binary and multi-class classification.
Implements: IClassificationMetric<T>
For Beginners
MCC is one of the best single-number metrics for classification, especially with imbalanced classes. It uses all four quadrants of the confusion matrix and produces a high score only when the model does well on both positives and negatives.
How It Works
For binary classification: MCC = (TPTN - FPFN) / sqrt((TP+FP)(TP+FN)(TN+FP)(TN+FN))
Interpretation:
- MCC = +1: Perfect prediction
- MCC = 0: No better than random
- MCC = -1: Complete disagreement (predictions are inverted)
Advantages over other metrics:
- Works well with imbalanced classes (unlike accuracy)
- Considers all parts of confusion matrix (unlike F1)
- Is symmetric: swapping positives/negatives gives same |MCC|
Research reference: Matthews (1975), Chicco & Jurman (2020) recommend MCC over F1.
Constructors
| Constructor | Summary |
|---|---|
MatthewsCorrelationCoefficientMetric() |
Initializes a new MCC metric with default positive label (1). |
MatthewsCorrelationCoefficientMetric(T positiveLabel) |
Initializes a new MCC metric with an explicit positive label. |
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> predictions, ReadOnlySpan<T> actuals, ConfidenceIntervalMethod ciMethod, double confidenceLevel, int bootstrapSamples, int? randomSeed) |
|
T Compute(ReadOnlySpan<T> predictions, ReadOnlySpan<T> actuals) |