Skip to content

Commit

Permalink
DOC Mention factor x2 between MAE and mean pinball loss (scikit-learn…
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxwellLZH committed Jun 16, 2022
1 parent 2e3a047 commit ada2f6b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doc/modules/model_evaluation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2562,7 +2562,7 @@ performance of `quantile regression
\text{pinball}(y, \hat{y}) = \frac{1}{n_{\text{samples}}} \sum_{i=0}^{n_{\text{samples}}-1} \alpha \max(y_i - \hat{y}_i, 0) + (1 - \alpha) \max(\hat{y}_i - y_i, 0)
The pinball loss is equivalent to :func:`mean_absolute_error` when the quantile
The value of pinball loss is equivalent to half of :func:`mean_absolute_error` when the quantile
parameter ``alpha`` is set to 0.5.


Expand Down
12 changes: 12 additions & 0 deletions sklearn/metrics/tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,3 +613,15 @@ def test_dummy_quantile_parameter_tuning():
).fit(X, y)

assert grid_search.best_params_["quantile"] == pytest.approx(alpha)


def test_pinball_loss_relation_with_mae():
# Test that mean_pinball loss with alpha=0.5 if half of mean absolute error
rng = np.random.RandomState(714)
n = 100
y_true = rng.normal(size=n)
y_pred = y_true.copy() + rng.uniform(n)
assert (
mean_absolute_error(y_true, y_pred)
== mean_pinball_loss(y_true, y_pred, alpha=0.5) * 2
)

0 comments on commit ada2f6b

Please sign in to comment.