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 LogLoss

From Leeroopedia


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

Overview

Binary logarithmic loss measuring the quality of probabilistic predictions.

Description

LogLoss (also called binary cross-entropy) quantifies the performance of a binary classifier that outputs probabilities between 0 and 1. It measures the negative log-likelihood of the correct label given the predicted probability, with lower values indicating better calibrated probability estimates. The formula is -log(p) for true positives and -log(1-p) for true negatives, where p is the predicted probability of the positive class.

Usage

Use LogLoss when evaluating binary classifiers that produce probability estimates rather than hard labels. It's particularly useful for assessing probability calibration, as it heavily penalizes confident incorrect predictions. Lower log loss values indicate better probabilistic predictions, making it ideal for applications where prediction confidence matters, such as risk assessment or decision-making under uncertainty.

Code Reference

Source Location

Signature

class LogLoss(metrics.base.MeanMetric, metrics.base.BinaryMetric):
    def __init__(self, cm=None, pos_val=True):
        pass

Import

from river import metrics

I/O Contract

Method Parameters Returns Description
update y_true (bool), y_pred (float or dict) None Updates with true label and probability
get - float Returns average log loss (lower is better)

Note: requires_labels property returns False (requires probabilities, not hard labels).

Usage Examples

from river import metrics

y_true = [True, False, False, True]
y_pred = [0.9,  0.1,   0.2,   0.65]

metric = metrics.LogLoss()
for yt, yp in zip(y_true, y_pred):
    metric.update(yt, yp)
    print(metric.get())
# 0.105360
# 0.105360
# 0.144621
# 0.216161

print(metric)
# LogLoss: 0.216162

# Lower log loss is better
# Perfect predictions (1.0 for True, 0.0 for False) → log loss ≈ 0
# Random predictions (0.5 for all) → log loss ≈ 0.693

# Can also accept probability dictionaries
y_pred_dict = [
    {False: 0.1, True: 0.9},
    {False: 0.9, True: 0.1},
    {False: 0.8, True: 0.2},
    {False: 0.35, True: 0.65}
]

metric2 = metrics.LogLoss()
for yt, yp in zip(y_true, y_pred_dict):
    metric2.update(yt, yp)

print(metric2)
# LogLoss: 0.216162

Related Pages

Page Connections

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