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 GeometricMean

From Leeroopedia


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

Overview

Geometric mean of class-wise sensitivity (recall) for imbalanced classification evaluation.

Description

GeometricMean computes the nth root of the product of class-wise sensitivities (recalls), where n is the number of classes. The formula is gm = (s1 × s2 × ... × sn)^(1/n), where si is the sensitivity of class i. This metric is particularly effective for imbalanced datasets as it's independent of class distribution and poor performance on any single class significantly lowers the overall score.

Usage

Use GeometricMean when evaluating classifiers on imbalanced datasets where all classes are equally important. Unlike arithmetic averages, the geometric mean severely penalizes poor performance on minority classes, making it ideal for scenarios where you cannot afford to ignore any class. A classifier must perform well across all classes to achieve a high geometric mean score.

Code Reference

Source Location

Signature

class GeometricMean(metrics.base.MultiClassMetric):
    def __init__(self, cm=None):
        pass

Import

from river import metrics

I/O Contract

Method Parameters Returns Description
update y_true, y_pred, [w] None Updates metric with true and predicted labels
get - float Returns geometric mean of class sensitivities (0.0 to 1.0)

Usage Examples

from river import metrics

y_true = ['cat', 'ant', 'cat', 'cat', 'ant', 'bird', 'bird']
y_pred = ['ant', 'ant', 'cat', 'cat', 'ant', 'cat', 'bird']

metric = metrics.GeometricMean()

for yt, yp in zip(y_true, y_pred):
    metric.update(yt, yp)

print(metric)
# GeometricMean: 69.34%

# The metric computes:
# Sensitivity(cat) = 2/3 = 66.67%
# Sensitivity(ant) = 2/2 = 100%
# Sensitivity(bird) = 1/2 = 50%
# GeometricMean = (0.6667 × 1.0 × 0.5)^(1/3) = 0.6934

# Note how the low sensitivity on 'bird' pulls down
# the overall score more than an arithmetic mean would

Related Pages

Page Connections

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