average_precision_score not working as expected

### Describe the bug

When compute AP with average_precision_score, I get unexpected results. The y_scores (output from the models) are very low for positive samples, so my AP should be very low. Instead I get a perfect 1.0 AP score.

### Steps/Code to Reproduce

```python
from sklearn.metrics import average_precision_score

# labels
y_true = [1, 1, 1, 1, 1]  # 5 positives
# Predicted scores
y_scores = [0.1, 0.3, 0.1, 0.2, 0.1]  # Model's confidence in predictions

# Calculate average precision
average_precision = average_precision_score(y_true, y_scores)
print("AP score:", average_precision)
```

### Expected Results

An AP score close to 0.

### Actual Results

AP score: 1.0

### Versions

```shell
System:
    python: 3.9.19 (main, May  6 2024, 19:43:03)  [GCC 11.2.0]
executable: /bin/python
   machine: Linux-5.15.0-121-generic-x86_64-with-glibc2.31

Python dependencies:
      sklearn: 1.5.2
          pip: 24.2
   setuptools: 75.1.0
        numpy: 1.26.4
        scipy: 1.13.1
       Cython: None
       pandas: 1.4.0
   matplotlib: 3.5.3
       joblib: 1.4.2
threadpoolctl: 3.5.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
    num_threads: 32
         prefix: libopenblas
       filepath: user/anaconda3/envs/perception39/lib/python3.9/site-packages/numpy.libs/libopenblas64_p-r0-0cf96a72.3.23.dev.so
        version: 0.3.23.dev
threading_layer: pthreads
   architecture: SkylakeX

       user_api: blas
   internal_api: openblas
    num_threads: 32
         prefix: libopenblas
       filepath: user/anaconda3/envs/perception39/lib/python3.9/site-packages/scipy.libs/libopenblasp-r0-01191904.3.27.so
        version: 0.3.27
threading_layer: pthreads
   architecture: SkylakeX

       user_api: openmp
   internal_api: openmp
    num_threads: 32
         prefix: libgomp
       filepath: user/anaconda3/envs/perception39/lib/python3.9/site-packages/scikit_learn.libs/libgomp-a34b3233.so.1.0.0
        version: None
```

COMMENT:
We can compare [<code>sklearn.metrics.average_precision_score</code>](https://scikit-learn.org/1.5/modules/generated/sklearn.metrics.average_precision_score.html) with PyTorch's version [<code>torcheval.metrics.functional.binary_auprc</code>](https://pytorch.org/torcheval/main/generated/torcheval.metrics.functional.binary_auprc.html#torcheval.metrics.functional.binary_auprc).

We can define a test function to compare numerical results between scikit-learn and PyTorch:

```python
import sklearn
from sklearn.metrics import average_precision_score
import numpy as np
from numpy.testing import assert_allclose
import torch
from torcheval.metrics.functional import binary_auprc as average_precision_score_torch

def compare_average_precision_scores(y_true, y_score):
    
    actual = average_precision_score_torch(torch.tensor(y_score), torch.tensor(y_true))
    desired = average_precision_score(y_true, y_score)
        
    return assert_allclose(np.float64(actual), np.float64(desired))
```

I ran several test cases, including OP's, and they all passed. Therefore, if we have some counterexamples along this direction, we will have a better chance of understanding the bug.

Labels: Bug