d2_pinball_score
- sklearn.metrics.d2_pinball_score(y_true, y_pred, *, sample_weight=None, alpha=0.5, multioutput='uniform_average')
regression score function, fraction of pinball loss explained.
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 score of 0.0.
Read more in the User Guide.
Ground truth (correct) target values.
Estimated target values.
Sample weights.
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.
Defines aggregating of multiple output values. Array-like value defines weights used to average scores.
Returns a full set of errors in case of multioutput input.
Scores of all outputs are averaged with uniform weight.
The score with a pinball deviance
or ndarray of scores if multioutput='raw_values'.
Like , 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 string name scorer to use along with tools such as
GridSearchCV or
RandomizedSearchCV.
Instead, you can create a scorer object using
make_scorer, with any desired parameter settings.
See the Examples section for details.
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/
>>> from sklearn.metrics import d2_pinball_score
>>> y_true = [1, 2, 3]
>>> y_pred = [1, 3, 3]
>>> d2_pinball_score(y_true, y_pred)
0.5
>>> d2_pinball_score(y_true, y_pred, alpha=0.9)
0.666...
>>> d2_pinball_score(y_true, y_pred, alpha=0.1)
-1.999...
>>> d2_pinball_score(y_true, y_true, alpha=0.1)
1.0
Creating a scorer object with make_scorer:
>>> import numpy as np
>>> from sklearn.metrics import make_scorer
>>> from sklearn.model_selection import GridSearchCV
>>> from sklearn.linear_model import QuantileRegressor
>>> X = np.array([[1], [2], [3], [4]])
>>> y = np.array([2.5, 0.0, 2, 8])
>>> pinball_95_scorer = make_scorer(d2_pinball_score, alpha=0.95)
>>> grid = GridSearchCV(
... QuantileRegressor(quantile=0.95),
... param_grid={"fit_intercept": [True, False]},
... scoring=pinball_95_scorer,
... cv=2,
... ).fit(X, y)
>>> grid.best_params_
{'fit_intercept': True}