Skip to content
Back to skills

D2 Pinball Score

ASecurity

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

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

Security analysis

A100/100

Scanned September 11, 2026

npx -y skills add qhjqhj00/research-skills-pool --skill d2-pinball-score --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of D2 Pinball Score?

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

Security grade badge for D2 Pinball Score
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/qhjqhj00-d2-pinball-score/badge)](https://www.skillsdirectory.com/skills/qhjqhj00-d2-pinball-score)

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: d2-pinball-score
description: Compute the d2_pinball_score metric — provided by scikit-learn. Use when the user has predictions and ground-truth and needs to compute d2_pinball_score, or asks how to score with d2_pinball_score.
metadata:
  skill_kind: metric
  source_lib: scikit-learn
  import_path: sklearn.metrics.d2_pinball_score
  source: library_introspection
---

# d2-pinball-score

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

## When to invoke this skill

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

## Reference signature

```python
from sklearn.metrics import d2_pinball_score

# d2_pinball_score(y_true, y_pred, *, sample_weight=None, alpha=0.5, multioutput='uniform_average')
```

## Library docstring

```
:math:`D^2` regression score function, fraction of pinball loss explained.

Best possible score is 1.0 and it can be negative (because the model can be
arbitrarily worse). A model that always uses the empirical alpha-quantile of
`y_true` as constant prediction, disregarding the input features,
gets a :math:`D^2` score of 0.0.

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

.. versionadded:: 1.1

Parameters
----------
y_true : array-like of shape (n_samples,) or (n_samples, n_outputs)
    Ground truth (correct) target values.

y_pred : array-like of shape (n_samples,) or (n_samples, n_outputs)
    Estimated target values.

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

alpha : float, default=0.5
    Slope of the pinball deviance. It determines the quantile level alpha
    for which the pinball deviance and also D2 are optimal.
    The default `alpha=0.5` is equivalent to `d2_absolute_error_score`.

multioutput : {'raw_values', 'uniform_average'} or array-like of shape             (n_outputs,), default='uniform_average'
    Defines aggregating of multiple output values.
    Array-like value defines weights used to average scores.

    'raw_values' :
        Returns a full set of errors in case of multioutput input.

    'uniform_average' :
        Scores of all outputs are averaged with uniform weight.

Returns
-------
score : float or ndarray of floats
    The :math:`D^2` score with a pinball deviance
    or ndarray of scores if `multioutput='raw_values'`.

Notes
-----
Like :math:`R^2`, :math:`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 point and will return a NaN
value if n_samples is less than two.

This metric is not a built-in :ref:`string name scorer
<scoring_string_names>` to use along with tools such as
:class:`~sklearn.model_selection.GridSearchCV` or
:class:`~sklearn.model_selection.RandomizedSearchCV`.
Instead, you can :ref:`create a scorer object <scoring_adapt_metric>` using
:func:`~sklearn.metrics.make_scorer`, with any desired parameter settings.
See the `Examples` section for details.

 References
----------
.. [1] Eq. (7) of `Ko
```

## Quick recipe

```python
import sklearn.metrics as _m
score = _m.d2_pinball_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)`.

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.