Compute the d2_tweedie_score metric — provided by scikit-learn. Use when the user has predictions and ground-truth and needs to compute d2_tweedie_score, or asks how to score with d2_tweedie_score.
Scanned 9/11/2026
Install to Claude Code
npx -y skills add qhjqhj00/research-skills-pool --skill d2-tweedie-score --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of D2 Tweedie Score?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/qhjqhj00-d2-tweedie-score)More formats (shields.io, HTML) on the badges page.
---
name: d2-tweedie-score
description: Compute the d2_tweedie_score metric — provided by scikit-learn. Use when the user has predictions and ground-truth and needs to compute d2_tweedie_score, or asks how to score with d2_tweedie_score.
metadata:
skill_kind: metric
source_lib: scikit-learn
import_path: sklearn.metrics.d2_tweedie_score
source: library_introspection
---
# d2-tweedie-score
> Metric `d2_tweedie_score` from `scikit-learn` (sklearn.metrics.d2_tweedie_score)
## When to invoke this skill
The user has predictions + ground truth and asks to evaluate with d2_tweedie_score, or
mentions `sklearn.metrics.d2_tweedie_score` directly, or wants the standard scikit-learn implementation.
## Reference signature
```python
from sklearn.metrics import d2_tweedie_score
# d2_tweedie_score(y_true, y_pred, *, sample_weight=None, power=0)
```
## Library docstring
```
:math:`D^2` regression score function, fraction of Tweedie deviance 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 mean of `y_true` as
constant prediction, disregarding the input features, gets a D^2 score of 0.0.
Read more in the :ref:`User Guide <d2_score>`.
.. versionadded:: 1.0
Parameters
----------
y_true : array-like of shape (n_samples,)
Ground truth (correct) target values.
y_pred : array-like of shape (n_samples,)
Estimated target values.
sample_weight : array-like of shape (n_samples,), default=None
Sample weights.
power : float, default=0
Tweedie power parameter. Either power <= 0 or power >= 1.
The higher `p` the less weight is given to extreme
deviations between true and predicted targets.
- power < 0: Extreme stable distribution. Requires: y_pred > 0.
- power = 0 : Normal distribution, output corresponds to r2_score.
y_true and y_pred can be any real numbers.
- power = 1 : Poisson distribution. Requires: y_true >= 0 and
y_pred > 0.
- 1 < p < 2 : Compound Poisson distribution. Requires: y_true >= 0
and y_pred > 0.
- power = 2 : Gamma distribution. Requires: y_true > 0 and y_pred > 0.
- power = 3 : Inverse Gaussian distribution. Requires: y_true > 0
and y_pred > 0.
- otherwise : Positive stable distribution. Requires: y_true > 0
and y_pred > 0.
Returns
-------
z : float
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 single samples and will return a NaN
value if n_samples is less than two.
References
----------
.. [1] Eq. (3.11) of Hastie, Trevor J., Robert Tibshirani and Martin J.
Wainwright. "Statistical Learning with Sparsity: The Lasso and
Generalizations." (2015). https://hastie.su.domains/StatLearnSparsity/
Examples
--------
>>> from sklearn.metrics import d2_tweedie_score
>>> y_true = [0.5, 1, 2.5, 7]
>>> y_pred = [1, 1, 5, 3.5]
>>> d2_tweedie_score(y_true, y_pred)
0.285...
>>> d2_tweedie_score(y_
```
## Quick recipe
```python
import sklearn.metrics as _m
score = _m.d2_tweedie_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!