Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Online ml River Metrics ExactMatch

From Leeroopedia


Knowledge Sources
Domains Online_Learning, Evaluation_Metrics, Multi_Label_Classification
Last Updated 2026-02-08 16:00 GMT

Overview

Exact match score requiring all labels in a sample to be correctly predicted.

Description

ExactMatch is the strictest multi-label metric, measuring the fraction of samples where all labels are correctly classified. A sample counts as correct only if the predicted label set exactly matches the true label set. It returns 1 for exact matches and 0 for any mismatch, then averages across all samples. This provides a conservative measure of multi-label classification quality.

Usage

Use ExactMatch when partial correctness is unacceptable and you need all labels in a sample to be predicted correctly. It's appropriate for applications where getting even one label wrong makes the entire prediction useless, such as document categorization systems where all relevant categories must be identified, or medical diagnosis where missing or adding a condition could be critical.

Code Reference

Source Location

Signature

class ExactMatch(metrics.base.MeanMetric, MultiOutputClassificationMetric):
    def __init__(self, cm=None):
        pass

Import

from river import metrics

I/O Contract

Method Parameters Returns Description
update y_true (dict), y_pred (dict), [w] None Updates with true and predicted label sets
get - float Returns exact match ratio (0.0 to 1.0)

Usage Examples

from river import metrics

y_true = [
    {0: False, 1: True, 2: True},
    {0: True, 1: True, 2: False},
    {0: True, 1: True, 2: False},
]

y_pred = [
    {0: True, 1: True, 2: True},   # Wrong on label 0
    {0: True, 1: False, 2: False}, # Wrong on label 1
    {0: True, 1: True, 2: False},  # Perfect match
]

metric = metrics.multioutput.ExactMatch()
for yt, yp in zip(y_true, y_pred):
    metric.update(yt, yp)

print(metric)
# ExactMatch: 33.33%

# Only 1 out of 3 samples had all labels correct
# This demonstrates the strictness of exact match

# Compare with less strict metrics
# If we computed accuracy per label and averaged:
# Sample 1: 2/3 labels correct
# Sample 2: 2/3 labels correct
# Sample 3: 3/3 labels correct
# Average per-label accuracy: 2.33/3 = 77.78%
# But ExactMatch is only 33.33%

# Example showing perfect score
y_true_perfect = [
    {0: True, 1: False, 2: True},
    {0: False, 1: True, 2: False},
]

y_pred_perfect = [
    {0: True, 1: False, 2: True},
    {0: False, 1: True, 2: False},
]

metric_perfect = metrics.multioutput.ExactMatch()
for yt, yp in zip(y_true_perfect, y_pred_perfect):
    metric_perfect.update(yt, yp)

print(metric_perfect)
# ExactMatch: 100.00%

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment