Skip to content

Conversation

@cakedev0
Copy link
Owner

@cakedev0 cakedev0 commented Sep 14, 2025

WIP

Follow up to PR scikit-learn#32100 and esp. discussion here: scikit-learn#32100 (comment)

TODO (bottom-up order):

  • do the core changes in the algorithm
  • validate correctness with test_absolute_errors_precomputation_function (now renamed test_pinball_loss_precomputation_function)
  • change the MAE criterion class to a QuantileRegression class
  • modify the public API of the class and pass down the "q" parameter to the QuantileRegression class:
    • validate parameter naming
  • write some high-level tests (even though the current modified test_absolute_errors_precomputation_function makes me already fairly confident):
  • update de public API doc: I need
  • update the user-guide: I should
  • doc: add examples? Maybe one with a

Reference Issues/PRs

scikit-learn#32100

What does this implement/fix? Explain your changes.

Any other comments?

Maths:

We consider a weighted dataset ${(y_i, w_i)}_{i}$ with non-negative weights $w_i$.

For a scalar prediction $q$, the weighted pinball loss is

$$ L_\alpha(q) = \sum_{i} w_i \big( \alpha \max(y_i - q, 0) + (1 - \alpha)\max(q - y_i, 0) \big) $$

Equivalently, splitting by whether $y_i \ge q$ or $y_i < q$:

$$ L_\alpha(q) = \alpha \sum_{i: y_i \ge q} w_i (y_i - q) + (1 - \alpha) \sum_{i: y_i < q} w_i (q - y_i) $$

To evaluate this efficiently, introduce the aggregates

$$ W^+(q) = \sum_{i: y_i \ge q} w_i, \qquad Y^+(q) = \sum_{i: y_i \ge q} w_i y_i, $$

$$ W^-(q) = \sum_{i: y_i < q} w_i, \qquad Y^-(q) = \sum_{i: y_i < q} w_i y_i. $$

Using these, the loss admits the "O(1)" form

$$ L_\alpha(q) = \alpha \big( Y^+(q) - q W^+(q) \big) + (1 - \alpha) \big( q W^-(q) - Y^-(q) \big). $$

Or in the code:

q * (above.weighted_sum - quantile * above.total_weight)
+ (1 - q) * (quantile * below.total_weight - below.weighted_sum)

@cakedev0 cakedev0 changed the base branch from mae-split-optim to main December 15, 2025 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants