Talip7/scikit-learn-issues-multilabel huggingface dataset:
[Bug] `sklearn.base.BaseEstimator` subclasses not decoratable

### Describe the bug

Greetings, wondrous `sklearn` maintainers. This is @leycec, the maintainer of @beartype – a third-generation hybrid static-runtime type-checker with far too many hyphens in its description. Who even knows what that means at this point. The point is that I recently [fielded an issue](https://github.com/beartype/beartype/issues/340) from [one of my favourite users](https://github.com/tvdboom) requesting support for `sklearn` "metadata routing." I don't even know what that is... *but it sounds hot.*

Sadly, @beartype cannot provide this support – because the `sklearn.base.BaseEstimator` subclass fails to support decoration at a core level. That's outside our scope of control. But first, the minimal reproducible example (MRE) exhibiting this issue:

### Steps/Code to Reproduce

```python
import sklearn
from sklearn.base import BaseEstimator

sklearn.set_config(enable_metadata_routing=True)

class A(BaseEstimator):
    def fit(self, X, y, sample_weight=None):
        return self

A.set_fit_request = A.set_fit_request
a = A().set_fit_request(sample_weight=True)
```

### Expected Results

No exception is raised.

### Actual Results

```python
Traceback (most recent call last):
  File "/home/leycec/tmp/mopy.py", line 13, in <module>
    a = A().set_fit_request(sample_weight=True)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: RequestMethod.__get__.<locals>.func() takes 0 positional arguments but 1 was given
```

### Versions

```shell
System:
    python: 3.12.2 (main, Mar  9 2024, 18:58:45) [GCC 13.2.1 20240113]
executable: /usr/bin/python3.12
   machine: Linux-6.1.67-gentoo-x86_64-AMD_Athlon-tm-_II_X2_240_Processor-with-glibc2.38

Python dependencies:
      sklearn: 1.3.2
          pip: 24.0
   setuptools: 69.1.1
        numpy: 1.26.4
        scipy: 1.12.0
       Cython: 3.0.8
       pandas: 2.2.0
   matplotlib: 3.8.3
       joblib: 1.3.2
threadpoolctl: 3.3.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
    num_threads: 6
         prefix: libopenblas
       filepath: /usr/lib64/libopenblas_barcelonap-r0.3.25.so
        version: 0.3.25
threading_layer: openmp
   architecture: BARCELONA

       user_api: openmp
   internal_api: openmp
    num_threads: 2
         prefix: libgomp
       filepath: /usr/lib/gcc/x86_64-pc-linux-gnu/13/libgomp.so.1.0.0
        version: None
```
```

COMMENT:
Thanks so much, @glemaitre. There's certainly a special madness happening here. `sklearn` is so amazing... *but also scary.* :scream:

Labels: Bug
[Bug] `sklearn.base.BaseEstimator` subclasses not decoratable

### Describe the bug

Greetings, wondrous `sklearn` maintainers. This is @leycec, the maintainer of @beartype – a third-generation hybrid static-runtime type-checker with far too many hyphens in its description. Who even knows what that means at this point. The point is that I recently [fielded an issue](https://github.com/beartype/beartype/issues/340) from [one of my favourite users](https://github.com/tvdboom) requesting support for `sklearn` "metadata routing." I don't even know what that is... *but it sounds hot.*

Sadly, @beartype cannot provide this support – because the `sklearn.base.BaseEstimator` subclass fails to support decoration at a core level. That's outside our scope of control. But first, the minimal reproducible example (MRE) exhibiting this issue:

### Steps/Code to Reproduce

```python
import sklearn
from sklearn.base import BaseEstimator

sklearn.set_config(enable_metadata_routing=True)

class A(BaseEstimator):
    def fit(self, X, y, sample_weight=None):
        return self

A.set_fit_request = A.set_fit_request
a = A().set_fit_request(sample_weight=True)
```

### Expected Results

No exception is raised.

### Actual Results

```python
Traceback (most recent call last):
  File "/home/leycec/tmp/mopy.py", line 13, in <module>
    a = A().set_fit_request(sample_weight=True)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: RequestMethod.__get__.<locals>.func() takes 0 positional arguments but 1 was given
```

### Versions

```shell
System:
    python: 3.12.2 (main, Mar  9 2024, 18:58:45) [GCC 13.2.1 20240113]
executable: /usr/bin/python3.12
   machine: Linux-6.1.67-gentoo-x86_64-AMD_Athlon-tm-_II_X2_240_Processor-with-glibc2.38

Python dependencies:
      sklearn: 1.3.2
          pip: 24.0
   setuptools: 69.1.1
        numpy: 1.26.4
        scipy: 1.12.0
       Cython: 3.0.8
       pandas: 2.2.0
   matplotlib: 3.8.3
       joblib: 1.3.2
threadpoolctl: 3.3.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
    num_threads: 6
         prefix: libopenblas
       filepath: /usr/lib64/libopenblas_barcelonap-r0.3.25.so
        version: 0.3.25
threading_layer: openmp
   architecture: BARCELONA

       user_api: openmp
   internal_api: openmp
    num_threads: 2
         prefix: libgomp
       filepath: /usr/lib/gcc/x86_64-pc-linux-gnu/13/libgomp.so.1.0.0
        version: None
```
```

COMMENT:
Hehe, this is a nice one. Love the minimal reproducible. That "method" is a dynamically generated descriptor, and I'm surprised `A.descriptor = A.descriptor` fails. I'll have a look.

Labels: Bug
[Bug] `sklearn.base.BaseEstimator` subclasses not decoratable

### Describe the bug

Greetings, wondrous `sklearn` maintainers. This is @leycec, the maintainer of @beartype – a third-generation hybrid static-runtime type-checker with far too many hyphens in its description. Who even knows what that means at this point. The point is that I recently [fielded an issue](https://github.com/beartype/beartype/issues/340) from [one of my favourite users](https://github.com/tvdboom) requesting support for `sklearn` "metadata routing." I don't even know what that is... *but it sounds hot.*

Sadly, @beartype cannot provide this support – because the `sklearn.base.BaseEstimator` subclass fails to support decoration at a core level. That's outside our scope of control. But first, the minimal reproducible example (MRE) exhibiting this issue:

### Steps/Code to Reproduce

```python
import sklearn
from sklearn.base import BaseEstimator

sklearn.set_config(enable_metadata_routing=True)

class A(BaseEstimator):
    def fit(self, X, y, sample_weight=None):
        return self

A.set_fit_request = A.set_fit_request
a = A().set_fit_request(sample_weight=True)
```

### Expected Results

No exception is raised.

### Actual Results

```python
Traceback (most recent call last):
  File "/home/leycec/tmp/mopy.py", line 13, in <module>
    a = A().set_fit_request(sample_weight=True)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: RequestMethod.__get__.<locals>.func() takes 0 positional arguments but 1 was given
```

### Versions

```shell
System:
    python: 3.12.2 (main, Mar  9 2024, 18:58:45) [GCC 13.2.1 20240113]
executable: /usr/bin/python3.12
   machine: Linux-6.1.67-gentoo-x86_64-AMD_Athlon-tm-_II_X2_240_Processor-with-glibc2.38

Python dependencies:
      sklearn: 1.3.2
          pip: 24.0
   setuptools: 69.1.1
        numpy: 1.26.4
        scipy: 1.12.0
       Cython: 3.0.8
       pandas: 2.2.0
   matplotlib: 3.8.3
       joblib: 1.3.2
threadpoolctl: 3.3.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
    num_threads: 6
         prefix: libopenblas
       filepath: /usr/lib64/libopenblas_barcelonap-r0.3.25.so
        version: 0.3.25
threading_layer: openmp
   architecture: BARCELONA

       user_api: openmp
   internal_api: openmp
    num_threads: 2
         prefix: libgomp
       filepath: /usr/lib/gcc/x86_64-pc-linux-gnu/13/libgomp.so.1.0.0
        version: None
```
```

COMMENT:
Fix patch: https://github.com/scikit-learn/scikit-learn/pull/28651

Labels: Bug
[Bug] `sklearn.base.BaseEstimator` subclasses not decoratable

### Describe the bug

Greetings, wondrous `sklearn` maintainers. This is @leycec, the maintainer of @beartype – a third-generation hybrid static-runtime type-checker with far too many hyphens in its description. Who even knows what that means at this point. The point is that I recently [fielded an issue](https://github.com/beartype/beartype/issues/340) from [one of my favourite users](https://github.com/tvdboom) requesting support for `sklearn` "metadata routing." I don't even know what that is... *but it sounds hot.*

Sadly, @beartype cannot provide this support – because the `sklearn.base.BaseEstimator` subclass fails to support decoration at a core level. That's outside our scope of control. But first, the minimal reproducible example (MRE) exhibiting this issue:

### Steps/Code to Reproduce

```python
import sklearn
from sklearn.base import BaseEstimator

sklearn.set_config(enable_metadata_routing=True)

class A(BaseEstimator):
    def fit(self, X, y, sample_weight=None):
        return self

A.set_fit_request = A.set_fit_request
a = A().set_fit_request(sample_weight=True)
```

### Expected Results

No exception is raised.

### Actual Results

```python
Traceback (most recent call last):
  File "/home/leycec/tmp/mopy.py", line 13, in <module>
    a = A().set_fit_request(sample_weight=True)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: RequestMethod.__get__.<locals>.func() takes 0 positional arguments but 1 was given
```

### Versions

```shell
System:
    python: 3.12.2 (main, Mar  9 2024, 18:58:45) [GCC 13.2.1 20240113]
executable: /usr/bin/python3.12
   machine: Linux-6.1.67-gentoo-x86_64-AMD_Athlon-tm-_II_X2_240_Processor-with-glibc2.38

Python dependencies:
      sklearn: 1.3.2
          pip: 24.0
   setuptools: 69.1.1
        numpy: 1.26.4
        scipy: 1.12.0
       Cython: 3.0.8
       pandas: 2.2.0
   matplotlib: 3.8.3
       joblib: 1.3.2
threadpoolctl: 3.3.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
    num_threads: 6
         prefix: libopenblas
       filepath: /usr/lib64/libopenblas_barcelonap-r0.3.25.so
        version: 0.3.25
threading_layer: openmp
   architecture: BARCELONA

       user_api: openmp
   internal_api: openmp
    num_threads: 2
         prefix: libgomp
       filepath: /usr/lib/gcc/x86_64-pc-linux-gnu/13/libgomp.so.1.0.0
        version: None
```
```

COMMENT:
**Madness.** Sheer madness assaults my every sense! I especially love this part:

```python
A().method()
A.method = A.method
A().method()
```

It's almost ASCII art at this point. :smile:

Labels: Bug
HDBSCAN error with metric cosine

### Describe the bug

Inconsistent HDBSCAN behavior when given a metric that is not supported by KDTree or BallTree.

[docs](https://scikit-learn.org/stable/modules/generated/sklearn.cluster.HDBSCAN.html)

```
metric : str or callable, default=’euclidean’

    The metric to use when calculating distance between instances in a feature array.

        If metric is a string or callable, it must be one of the options allowed by [pairwise_distances](https://scikit-learn.org/stable/modules/generated/sklearn.metrics.pairwise_distances.html#sklearn.metrics.pairwise_distances) for its metric parameter.

        If metric is “precomputed”, X is assumed to be a distance matrix and must be square.
```

### Steps/Code to Reproduce

```py
from sklearn.cluster import HDBSCAN

clusterer = HDBSCAN(metric="cosine")
clusterer.fit([])
```

### Expected Results

no error

### Actual Results

InvalidParameterError: The 'metric' parameter of HDBSCAN must be a str among {'euclidean', 'p', 'rogerstanimoto', 'seuclidean', 'l1', 'l2', 'russellrao', 'cityblock', 'sokalmichener', 'precomputed', 'dice', 'manhattan', 'minkowski', 'pyfunc', 'jaccard', 'chebyshev', 'infinity', 'mahalanobis', 'hamming', 'braycurtis', 'haversine', 'canberra', 'sokalsneath'} or a callable. Got 'cosine' instead.

### Versions

```shell
System:
    python: 3.11.7 (main, Dec  4 2023, 18:10:11) [Clang 15.0.0 (clang-1500.1.0.2.5)]
executable: /opt/homebrew/opt/python@3.11/bin/python3.11
   machine: macOS-14.3.1-arm64-arm-64bit

Python dependencies:
      sklearn: 1.4.1.post1
          pip: 24.0
   setuptools: 69.0.2
        numpy: 1.26.4
        scipy: 1.12.0
       Cython: 0.29.37
       pandas: 2.2.1
   matplotlib: 3.8.3
       joblib: 1.3.2
threadpoolctl: 3.3.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
    num_threads: 16
         prefix: libopenblas
       filepath: /opt/homebrew/lib/python3.11/site-packages/numpy/.dylibs/libopenblas64_.0.dylib
        version: 0.3.23.dev
threading_layer: pthreads
   architecture: armv8

       user_api: openmp
   internal_api: openmp
    num_threads: 16
         prefix: libomp
       filepath: /opt/homebrew/lib/python3.11/site-packages/torch/.dylibs/libomp.dylib
        version: None

       user_api: openmp
   internal_api: openmp
    num_threads: 16
         prefix: libomp
       filepath: /opt/homebrew/lib/python3.11/site-packages/sklearn/.dylibs/libomp.dylib
        version: None

       user_api: blas
   internal_api: openblas
    num_threads: 16
         prefix: libopenblas
       filepath: /opt/homebrew/lib/python3.11/site-packages/scipy/.dylibs/libopenblas.0.dylib
        version: 0.3.21.dev
threading_layer: pthreads
   architecture: armv8
```

COMMENT:
Indeed, we need to modify the documentation mentioning that the supported metrics are based on KDTree and BallTree. Maybe a way to help is to provide a small piece of code that allows to discover:

```
from sklearn.neighbors import BallTree, KDTree
set(KDTree.valid_metrics + BallTree.valid_metrics)
```

Labels: Bug
HDBSCAN error with metric cosine

### Describe the bug

Inconsistent HDBSCAN behavior when given a metric that is not supported by KDTree or BallTree.

[docs](https://scikit-learn.org/stable/modules/generated/sklearn.cluster.HDBSCAN.html)

```
metric : str or callable, default=’euclidean’

    The metric to use when calculating distance between instances in a feature array.

        If metric is a string or callable, it must be one of the options allowed by [pairwise_distances](https://scikit-learn.org/stable/modules/generated/sklearn.metrics.pairwise_distances.html#sklearn.metrics.pairwise_distances) for its metric parameter.

        If metric is “precomputed”, X is assumed to be a distance matrix and must be square.
```

### Steps/Code to Reproduce

```py
from sklearn.cluster import HDBSCAN

clusterer = HDBSCAN(metric="cosine")
clusterer.fit([])
```

### Expected Results

no error

### Actual Results

InvalidParameterError: The 'metric' parameter of HDBSCAN must be a str among {'euclidean', 'p', 'rogerstanimoto', 'seuclidean', 'l1', 'l2', 'russellrao', 'cityblock', 'sokalmichener', 'precomputed', 'dice', 'manhattan', 'minkowski', 'pyfunc', 'jaccard', 'chebyshev', 'infinity', 'mahalanobis', 'hamming', 'braycurtis', 'haversine', 'canberra', 'sokalsneath'} or a callable. Got 'cosine' instead.

### Versions

```shell
System:
    python: 3.11.7 (main, Dec  4 2023, 18:10:11) [Clang 15.0.0 (clang-1500.1.0.2.5)]
executable: /opt/homebrew/opt/python@3.11/bin/python3.11
   machine: macOS-14.3.1-arm64-arm-64bit

Python dependencies:
      sklearn: 1.4.1.post1
          pip: 24.0
   setuptools: 69.0.2
        numpy: 1.26.4
        scipy: 1.12.0
       Cython: 0.29.37
       pandas: 2.2.1
   matplotlib: 3.8.3
       joblib: 1.3.2
threadpoolctl: 3.3.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
    num_threads: 16
         prefix: libopenblas
       filepath: /opt/homebrew/lib/python3.11/site-packages/numpy/.dylibs/libopenblas64_.0.dylib
        version: 0.3.23.dev
threading_layer: pthreads
   architecture: armv8

       user_api: openmp
   internal_api: openmp
    num_threads: 16
         prefix: libomp
       filepath: /opt/homebrew/lib/python3.11/site-packages/torch/.dylibs/libomp.dylib
        version: None

       user_api: openmp
   internal_api: openmp
    num_threads: 16
         prefix: libomp
       filepath: /opt/homebrew/lib/python3.11/site-packages/sklearn/.dylibs/libomp.dylib
        version: None

       user_api: blas
   internal_api: openblas
    num_threads: 16
         prefix: libopenblas
       filepath: /opt/homebrew/lib/python3.11/site-packages/scipy/.dylibs/libopenblas.0.dylib
        version: 0.3.21.dev
threading_layer: pthreads
   architecture: armv8
```

COMMENT:
Don't you think that it would be cool to fallback to `pairwise_distances` for other metrics?

Labels: Bug
HDBSCAN error with metric cosine

### Describe the bug

Inconsistent HDBSCAN behavior when given a metric that is not supported by KDTree or BallTree.

[docs](https://scikit-learn.org/stable/modules/generated/sklearn.cluster.HDBSCAN.html)

```
metric : str or callable, default=’euclidean’

    The metric to use when calculating distance between instances in a feature array.

        If metric is a string or callable, it must be one of the options allowed by [pairwise_distances](https://scikit-learn.org/stable/modules/generated/sklearn.metrics.pairwise_distances.html#sklearn.metrics.pairwise_distances) for its metric parameter.

        If metric is “precomputed”, X is assumed to be a distance matrix and must be square.
```

### Steps/Code to Reproduce

```py
from sklearn.cluster import HDBSCAN

clusterer = HDBSCAN(metric="cosine")
clusterer.fit([])
```

### Expected Results

no error

### Actual Results

InvalidParameterError: The 'metric' parameter of HDBSCAN must be a str among {'euclidean', 'p', 'rogerstanimoto', 'seuclidean', 'l1', 'l2', 'russellrao', 'cityblock', 'sokalmichener', 'precomputed', 'dice', 'manhattan', 'minkowski', 'pyfunc', 'jaccard', 'chebyshev', 'infinity', 'mahalanobis', 'hamming', 'braycurtis', 'haversine', 'canberra', 'sokalsneath'} or a callable. Got 'cosine' instead.

### Versions

```shell
System:
    python: 3.11.7 (main, Dec  4 2023, 18:10:11) [Clang 15.0.0 (clang-1500.1.0.2.5)]
executable: /opt/homebrew/opt/python@3.11/bin/python3.11
   machine: macOS-14.3.1-arm64-arm-64bit

Python dependencies:
      sklearn: 1.4.1.post1
          pip: 24.0
   setuptools: 69.0.2
        numpy: 1.26.4
        scipy: 1.12.0
       Cython: 0.29.37
       pandas: 2.2.1
   matplotlib: 3.8.3
       joblib: 1.3.2
threadpoolctl: 3.3.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
    num_threads: 16
         prefix: libopenblas
       filepath: /opt/homebrew/lib/python3.11/site-packages/numpy/.dylibs/libopenblas64_.0.dylib
        version: 0.3.23.dev
threading_layer: pthreads
   architecture: armv8

       user_api: openmp
   internal_api: openmp
    num_threads: 16
         prefix: libomp
       filepath: /opt/homebrew/lib/python3.11/site-packages/torch/.dylibs/libomp.dylib
        version: None

       user_api: openmp
   internal_api: openmp
    num_threads: 16
         prefix: libomp
       filepath: /opt/homebrew/lib/python3.11/site-packages/sklearn/.dylibs/libomp.dylib
        version: None

       user_api: blas
   internal_api: openblas
    num_threads: 16
         prefix: libopenblas
       filepath: /opt/homebrew/lib/python3.11/site-packages/scipy/.dylibs/libopenblas.0.dylib
        version: 0.3.21.dev
threading_layer: pthreads
   architecture: armv8
```

COMMENT:
I missed that we were having the option `algorithm="brute"`. So indeed, we should accept those metrics. It also means that we don't have a test that cover this use case. So this is not a documentation issue but a programmatic one.

Labels: Bug
HDBSCAN error with metric cosine

### Describe the bug

Inconsistent HDBSCAN behavior when given a metric that is not supported by KDTree or BallTree.

[docs](https://scikit-learn.org/stable/modules/generated/sklearn.cluster.HDBSCAN.html)

```
metric : str or callable, default=’euclidean’

    The metric to use when calculating distance between instances in a feature array.

        If metric is a string or callable, it must be one of the options allowed by [pairwise_distances](https://scikit-learn.org/stable/modules/generated/sklearn.metrics.pairwise_distances.html#sklearn.metrics.pairwise_distances) for its metric parameter.

        If metric is “precomputed”, X is assumed to be a distance matrix and must be square.
```

### Steps/Code to Reproduce

```py
from sklearn.cluster import HDBSCAN

clusterer = HDBSCAN(metric="cosine")
clusterer.fit([])
```

### Expected Results

no error

### Actual Results

InvalidParameterError: The 'metric' parameter of HDBSCAN must be a str among {'euclidean', 'p', 'rogerstanimoto', 'seuclidean', 'l1', 'l2', 'russellrao', 'cityblock', 'sokalmichener', 'precomputed', 'dice', 'manhattan', 'minkowski', 'pyfunc', 'jaccard', 'chebyshev', 'infinity', 'mahalanobis', 'hamming', 'braycurtis', 'haversine', 'canberra', 'sokalsneath'} or a callable. Got 'cosine' instead.

### Versions

```shell
System:
    python: 3.11.7 (main, Dec  4 2023, 18:10:11) [Clang 15.0.0 (clang-1500.1.0.2.5)]
executable: /opt/homebrew/opt/python@3.11/bin/python3.11
   machine: macOS-14.3.1-arm64-arm-64bit

Python dependencies:
      sklearn: 1.4.1.post1
          pip: 24.0
   setuptools: 69.0.2
        numpy: 1.26.4
        scipy: 1.12.0
       Cython: 0.29.37
       pandas: 2.2.1
   matplotlib: 3.8.3
       joblib: 1.3.2
threadpoolctl: 3.3.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
    num_threads: 16
         prefix: libopenblas
       filepath: /opt/homebrew/lib/python3.11/site-packages/numpy/.dylibs/libopenblas64_.0.dylib
        version: 0.3.23.dev
threading_layer: pthreads
   architecture: armv8

       user_api: openmp
   internal_api: openmp
    num_threads: 16
         prefix: libomp
       filepath: /opt/homebrew/lib/python3.11/site-packages/torch/.dylibs/libomp.dylib
        version: None

       user_api: openmp
   internal_api: openmp
    num_threads: 16
         prefix: libomp
       filepath: /opt/homebrew/lib/python3.11/site-packages/sklearn/.dylibs/libomp.dylib
        version: None

       user_api: blas
   internal_api: openblas
    num_threads: 16
         prefix: libopenblas
       filepath: /opt/homebrew/lib/python3.11/site-packages/scipy/.dylibs/libopenblas.0.dylib
        version: 0.3.21.dev
threading_layer: pthreads
   architecture: armv8
```

COMMENT:
I got this issue. I'll work on getting HDBSCAN work with cosine metric when the algorithm is set to brute. 
```
clusterer = HDBSCAN(metric="cosine", algorithm="brute")
```

Labels: Bug