Weighted MAPE behaviour on 0

### Describe the workflow you want to enable

Hello,

I create this ticket because I realized unexpected behaviour for Weighted MAPE when you weight for the real values and those values are 0.

By the formula:

<img width="217" height="73" alt="Image" src="https://github.com/user-attachments/assets/2e874378-3674-4861-9e4f-91866c7d23bd" />

In the case the weights are the same as the a_i, the values should cancel out (even at 0 because the limit is well defined and can be extended to 0) and coincide with this:

<img width="202" height="62" alt="Image" src="https://github.com/user-attachments/assets/0c6ac99d-d69f-4326-90c3-b97dd709e966" /> (1)

Looking at the current implementation:

https://github.com/scikit-learn/scikit-learn/blob/c60dae2060/sklearn/metrics/_regression.py#L408

what happens with zeros is that they are removed from the computation.


I understand this needs to be like this to allow for generic weights, that are not the real values, but this is creating an unexpected behaviour.
Maybe there should be another class that implements directly (1), to avoid problems with it.

Best,

Arnau

### Describe your proposed solution

I wold suggest create another classe wape that directly calculates:
sum(|y_pred- y|)/sum(|y|)
To avoid this unexpected behaviour.

### Describe alternatives you've considered, if relevant

I don't think changing the current class would be a good option since it is implemented in the only way that can allow for generic weights.

### Additional context

_No response_

COMMENT:
Thanks @virchan — I agree the implementation and docs for mean_absolute_percentage_error are consistent. My point is different: the metric usually called WAPE (Weighted Absolute Percentage Error) in the forecasting literature is defined as


<img width="258" height="72" alt="Image" src="https://github.com/user-attachments/assets/7a1d0139-0ee4-4834-b620-2108b413e979" />

and that exact quantity cannot be produced by the current mean_absolute_percentage_error(..., sample_weight=...) API. 
[Rob J Hyndman](https://robjhyndman.com/hyndsight/wape.html)

I initially thought that using

`mean_absolute_percentage_error(y_true, y_pred, sample_weight=y_true)`


would yield this metric, but it does not — because of how zero values and weights are handled. 

I checked beforehand the scikit-learn implementation and docs you mentioned. Because MAPE is computed using a denominator of max(eps, |y_i|) (to avoid division-by-zero) and sample weights are handled by the general sample_weight normalization logic in the metric code, WAPE cannot be reproduced.

That’s why I suggested either adding direct support for WAPE or providing an option to compute it cleanly within the current framework:

1. adding a dedicated wape() / weighted_absolute_percentage_error() function that implements directly (with a clear rule for the all-zero denominator case), or
2. exposing a safe, documented way to compute that same formula from existing APIs.

Either option would make it straightforward for users who find the standard WAPE definition in the implementation.

Thanks for reading and for the discussion — I appreciate the time the maintainers are putting into this.

Labels: module:metrics