Skip to content
Back to skills

Log Loss

ASecurity

Compute the log_loss metric — provided by scikit-learn. Use when the user has predictions and ground-truth and needs to compute log_loss, or asks how to score with log_loss.

  • 3 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 11, 2026
documentationpythonspring

Works with

  • cli

Security analysis

A100/100

Scanned September 11, 2026

npx -y skills add qhjqhj00/research-skills-pool --skill log-loss --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Log Loss?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Log Loss
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/qhjqhj00-log-loss/badge)](https://www.skillsdirectory.com/skills/qhjqhj00-log-loss)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: log-loss
description: Compute the log_loss metric — provided by scikit-learn. Use when the user has predictions and ground-truth and needs to compute log_loss, or asks how to score with log_loss.
metadata:
  skill_kind: metric
  source_lib: scikit-learn
  import_path: sklearn.metrics.log_loss
  source: library_introspection
---

# log-loss

> Metric `log_loss` from `scikit-learn` (sklearn.metrics.log_loss)

## When to invoke this skill

The user has predictions + ground truth and asks to evaluate with log_loss, or
mentions `sklearn.metrics.log_loss` directly, or wants the standard scikit-learn implementation.

## Reference signature

```python
from sklearn.metrics import log_loss

# log_loss(y_true, y_pred, *, normalize=True, sample_weight=None, labels=None)
```

## Library docstring

```
Log loss, aka logistic loss or cross-entropy loss.

This is the loss function used in (multinomial) logistic regression
and extensions of it such as neural networks, defined as the negative
log-likelihood of a logistic model that returns ``y_pred`` probabilities
for its training data ``y_true``.
The log loss is only defined for two or more labels.
For a single sample with true label :math:`y \in \{0,1\}` and
a probability estimate :math:`p = \operatorname{Pr}(y = 1)`, the log
loss is:

.. math::
    L_{\log}(y, p) = -(y \log (p) + (1 - y) \log (1 - p))

Read more in the :ref:`User Guide <log_loss>`.

Parameters
----------
y_true : array-like or label indicator matrix
    Ground truth (correct) labels for n_samples samples.

y_pred : array-like of float, shape = (n_samples, n_classes) or (n_samples,)
    Predicted probabilities, as returned by a classifier's
    predict_proba method. If ``y_pred.shape = (n_samples,)``
    the probabilities provided are assumed to be that of the
    positive class. The labels in ``y_pred`` are assumed to be
    ordered alphabetically, as done by
    :class:`~sklearn.preprocessing.LabelBinarizer`.

    `y_pred` values are clipped to `[eps, 1-eps]` where `eps` is the machine
    precision for `y_pred`'s dtype.

normalize : bool, default=True
    If true, return the mean loss per sample.
    Otherwise, return the sum of the per-sample losses.

sample_weight : array-like of shape (n_samples,), default=None
    Sample weights.

labels : array-like, default=None
    If not provided, labels will be inferred from y_true. If ``labels``
    is ``None`` and ``y_pred`` has shape (n_samples,) the labels are
    assumed to be binary and are inferred from ``y_true``.

    .. versionadded:: 0.18

Returns
-------
loss : float
    Log loss, aka logistic loss or cross-entropy loss.

Notes
-----
The logarithm used is the natural logarithm (base-e).

References
----------
C.M. Bishop (2006). Pattern Recognition and Machine Learning. Springer,
p. 209.

Examples
--------
>>> from sklearn.metrics import log_loss
>>> log_loss(["spam", "ham", "ham", "spam"],
...          [[.1, .9], [.9, .1], [.8, .2], [.35, .65]])
0.21616
```

## Quick recipe

```python
import sklearn.metrics as _m
score = _m.log_loss(y_true, y_pred)
```

## Don'ts

- Don't reimplement when the library version handles edge cases (NaN, ties, empty inputs) better than a hand-rolled formula.
- Always check the library version's argument order — sklearn is `(y_true, y_pred)` while torchmetrics is `(preds, target)`.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.