`make_scorer(needs_sample_weight=True)` wrongly injects `needs_sample_weight` into the scoring function

### Describe the bug


When using `make_scorer(..., needs_sample_weight=True)`, the generated scorer unexpectedly passes `needs_sample_weight=True` as a keyword argument to the scoring function itself, leading to `TypeError` unless **kwargs is manually added.


### Steps/Code to Reproduce


Minimal example:
```
import numpy as np
from sklearn.datasets import make_regression
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.model_selection import GridSearchCV
from sklearn.metrics import make_scorer

def weighted_mape(y_true, y_pred, sample_weight=None):
    return np.average(np.abs((y_true - y_pred) / (y_true + 1e-8)), weights=sample_weight)

scoring = make_scorer(weighted_mape, greater_is_better=False, needs_sample_weight=True)

X, y = make_regression(n_samples=100, n_features=5, random_state=0)
weights = np.random.rand(100)

model = GradientBoostingRegressor()
grid = GridSearchCV(model, param_grid={"n_estimators": [10]}, scoring=scoring, cv=3)
grid.fit(X, y, sample_weight=weights)
```



### Expected Results

**Expected behavior:**

`make_scorer(..., needs_sample_weight=True)` should cause `sample_weight` to be passed during cross-validation scoring.

The scoring function should not receive `needs_sample_weight=True` as a kwarg.




### Actual Results

**Actual behavior:**

The scoring function raises:

>TypeError: weighted_mape() got an unexpected keyword argument 'needs_sample_weight'
unless manually patched with **kwargs.

### Versions

```shell
System:
    python: 3.10.12 (main, Feb  4 2025, 14:57:36) [GCC 11.4.0]
executable: /home/X/XX/pax_env/bin/python
   machine: Linux-5.15.153.1-microsoft-standard-WSL2-x86_64-with-glibc2.35

Python dependencies:
      sklearn: 1.2.2
          pip: 22.0.2
   setuptools: 59.6.0
        numpy: 1.26.0
        scipy: 1.15.2
       Cython: None
       pandas: 1.5.3
   matplotlib: 3.7.1
       joblib: 1.2.0
threadpoolctl: 3.6.0

Built with OpenMP: True

threadpoolctl info:
       user_api: openmp
   internal_api: openmp
    num_threads: 14
         prefix: libgomp
       filepath: /home/X/XX/pax_env/lib/python3.10/site-packages/scikit_learn.libs/libgomp-a34b3233.so.1.0.0
        version: None

       user_api: blas
   internal_api: openblas
    num_threads: 14
         prefix: libopenblas
       filepath: /home/X/XX/pax_env/lib/python3.10/site-packages/numpy.libs/libopenblas64_p-r0-0cf96a72.3.23.dev.so
        version: 0.3.23.dev
threading_layer: pthreads
   architecture: Haswell

       user_api: blas
   internal_api: openblas
    num_threads: 14
         prefix: libscipy_openblas
       filepath: /home/X/XX/pax_env/lib/python3.10/site-packages/scipy.libs/libscipy_openblas-68440149.so
        version: 0.3.28
threading_layer: pthreads
   architecture: Haswell
```

COMMENT:
`needs_sample_weight` doesn't exist, and it didn't exist in 1.2.2:

https://github.com/scikit-learn/scikit-learn/blob/9aaed498795f68e5956ea762fef9c440ca9eb239/sklearn/metrics/_scorer.py#L604-L611

So the keyword is assumed to be something which needs to be forwarded to the scorer itself.

You're also using a very old version of scikit-learn. When it comes to metadata routing and sample weights, there's been a lot of developments in the last releases, and you probably want to use the latest release.

Labels: Bug, Needs Triage