Compute the d2_log_loss_score metric — provided by scikit-learn. Use when the user has predictions and ground-truth and needs to compute d2_log_loss_score, or asks how to score with d2_log_loss_score.
Scanned 9/11/2026
Install to Claude Code
npx -y skills add qhjqhj00/research-skills-pool --skill d2-log-loss-score --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of D2 Log Loss Score?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/qhjqhj00-d2-log-loss-score)More formats (shields.io, HTML) on the badges page.
---
name: d2-log-loss-score
description: Compute the d2_log_loss_score metric — provided by scikit-learn. Use when the user has predictions and ground-truth and needs to compute d2_log_loss_score, or asks how to score with d2_log_loss_score.
metadata:
skill_kind: metric
source_lib: scikit-learn
import_path: sklearn.metrics.d2_log_loss_score
source: library_introspection
---
# d2-log-loss-score
> Metric `d2_log_loss_score` from `scikit-learn` (sklearn.metrics.d2_log_loss_score)
## When to invoke this skill
The user has predictions + ground truth and asks to evaluate with d2_log_loss_score, or
mentions `sklearn.metrics.d2_log_loss_score` directly, or wants the standard scikit-learn implementation.
## Reference signature
```python
from sklearn.metrics import d2_log_loss_score
# d2_log_loss_score(y_true, y_pred, *, sample_weight=None, labels=None)
```
## Library docstring
```
:math:`D^2` score function, fraction of log loss explained.
Best possible score is 1.0 and it can be negative (because the model can be
arbitrarily worse). A model that always predicts the per-class proportions
of `y_true`, disregarding the input features, gets a D^2 score of 0.0.
Read more in the :ref:`User Guide <d2_score_classification>`.
.. versionadded:: 1.5
Parameters
----------
y_true : array-like or label indicator matrix
The actuals labels for the n_samples samples.
y_pred : array-like of 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`.
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``.
Returns
-------
d2 : float or ndarray of floats
The D^2 score.
Notes
-----
This is not a symmetric function.
Like R^2, D^2 score may be negative (it need not actually be the square of
a quantity D).
This metric is not well-defined for a single sample and will return a NaN
value if n_samples is less than two.
```
## Quick recipe
```python
import sklearn.metrics as _m
score = _m.d2_log_loss_score(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)`.

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!