Talip7/scikit-learn-issues-multilabel huggingface dataset:
Add zero_division for single class prediction in MCC

### Describe the bug

I have found a potential edge case issue with _sklearn.metrics.matthews_corrcoef_. The example provided in the documentation works as expected:

```python
from sklearn.metrics import matthews_corrcoef
matthews_corrcoef([1, 1, 1, -1], [1, -1, 1, 1])  # returns -1/3 OK
```

However, edge cases appear when either _y_ or _y_true_ have only one single label.

### Steps/Code to Reproduce

```python
from sklearn.metrics import matthews_corrcoef
matthews_corrcoef([1, 1, 1, 1], [1, 1, 1, 1])  # returns 0 instead of 1
matthews_corrcoef([0, 0, 0, 0], [0, 0, 0, 0])  # returns 0 instead of 1
```

### Expected Results

Outputs should be 1, not 0.

### Actual Results

Outputs are 0.

### Versions

```shell
System:
    python: 3.11.9 (main, Apr  2 2024, 08:25:04) [Clang 16.0.6 ]
executable: /tmp/sklearn-test/.venv/bin/python
   machine: macOS-14.2.1-arm64-arm-64bit

Python dependencies:
      sklearn: 1.4.2
          pip: 24.0
   setuptools: 69.5.1
        numpy: 1.26.4
        scipy: 1.13.0
       Cython: None
       pandas: None
   matplotlib: None
       joblib: 1.4.2
threadpoolctl: 3.5.0

Built with OpenMP: True

threadpoolctl info:
       user_api: openmp
   internal_api: openmp
    num_threads: 8
         prefix: libomp
       filepath: /tmp/sklearn-test/.venv/lib/python3.11/site-packages/torch/lib/libomp.dylib
        version: None

       user_api: blas
   internal_api: openblas
    num_threads: 8
         prefix: libopenblas
       filepath: /tmp/sklearn-test/.venv/lib/python3.11/site-packages/numpy/.dylibs/libopenblas64_.0.dylib
        version: 0.3.23.dev
threading_layer: pthreads
   architecture: armv8

       user_api: blas
   internal_api: openblas
    num_threads: 8
         prefix: libopenblas
       filepath: /tmp/sklearn-test/.venv/lib/python3.11/site-packages/scipy/.dylibs/libopenblas.0.dylib
        version: 0.3.26.dev
threading_layer: pthreads
   architecture: neoversen1

       user_api: openmp
   internal_api: openmp
    num_threads: 8
         prefix: libomp
       filepath: /tmp/sklearn-test/.venv/lib/python3.11/site-packages/sklearn/.dylibs/libomp.dylib
        version: None
```

COMMENT:
This was merged yesterday. We can close it.

Labels: Enhancement
Documentation says scikit-learn latest versions still supports Python 3.8

### Describe the issue linked to the documentation

https://scikit-learn.org/stable/install.html#installing-the-latest-release
"Scikit-learn 1.1 and later requires Python 3.8 or newer"

The latest versions of scikit-learn require Python 3.9 or newer.

### Suggest a potential alternative/fix

Specify which versions support 3.8 and which version support 3.9 or newer.

COMMENT:
@Aloqeely are you interested in making a PR?

Python version bumped in https://github.com/scikit-learn/scikit-learn/pull/27910

Labels: Documentation
Documentation says scikit-learn latest versions still supports Python 3.8

### Describe the issue linked to the documentation

https://scikit-learn.org/stable/install.html#installing-the-latest-release
"Scikit-learn 1.1 and later requires Python 3.8 or newer"

The latest versions of scikit-learn require Python 3.9 or newer.

### Suggest a potential alternative/fix

Specify which versions support 3.8 and which version support 3.9 or newer.

COMMENT:
Sure!

Labels: Documentation
`min_samples` in HDSCAN

### Describe the issue linked to the documentation

I find the description of the `min_samples` argument in sklearn.cluster.HDBSCAN confusing.

It says "The number of samples in a neighborhood for a point to be considered as a core point. This includes the point itself."

But if I understand everything correctly `min_samples` corresponds to the $k$ used to compute the core distance $\text{core}_k\left(x\right)$ for every sample $x$ where the $k$'th core distance for some sample $x$ is defined as the distance to the $k$'th nearest-neighbor of $x$ (counting itself). (-> which exactly what is happening in the code here: https://github.com/scikit-learn-contrib/hdbscan/blob/fc94241a4ecf5d3668cbe33b36ef03e6160d7ab7/hdbscan/_hdbscan_reachability.pyx#L45-L47, where it is called `min_points`)

I don't understand how both of these descriptions are equivalent. I would assume that other people might find that confusing as well.

Link in Code: https://github.com/scikit-learn/scikit-learn/blob/8721245511de2f225ff5f9aa5f5fadce663cd4a3/sklearn/cluster/_hdbscan/hdbscan.py#L441-L444

Link in Documentation: https://scikit-learn.org/stable/modules/generated/sklearn.cluster.DBSCAN.html#sklearn.cluster.DBSCAN

### Suggest a potential alternative/fix

_No response_

COMMENT:
cc @Micky774

Labels: Documentation, help wanted
`min_samples` in HDSCAN

### Describe the issue linked to the documentation

I find the description of the `min_samples` argument in sklearn.cluster.HDBSCAN confusing.

It says "The number of samples in a neighborhood for a point to be considered as a core point. This includes the point itself."

But if I understand everything correctly `min_samples` corresponds to the $k$ used to compute the core distance $\text{core}_k\left(x\right)$ for every sample $x$ where the $k$'th core distance for some sample $x$ is defined as the distance to the $k$'th nearest-neighbor of $x$ (counting itself). (-> which exactly what is happening in the code here: https://github.com/scikit-learn-contrib/hdbscan/blob/fc94241a4ecf5d3668cbe33b36ef03e6160d7ab7/hdbscan/_hdbscan_reachability.pyx#L45-L47, where it is called `min_points`)

I don't understand how both of these descriptions are equivalent. I would assume that other people might find that confusing as well.

Link in Code: https://github.com/scikit-learn/scikit-learn/blob/8721245511de2f225ff5f9aa5f5fadce663cd4a3/sklearn/cluster/_hdbscan/hdbscan.py#L441-L444

Link in Documentation: https://scikit-learn.org/stable/modules/generated/sklearn.cluster.DBSCAN.html#sklearn.cluster.DBSCAN

### Suggest a potential alternative/fix

_No response_

COMMENT:
Indeed, we used the docstring of the original implementation that reused the DBSCAN information. However, the parameter here have a different meaning: it define the core distance.

So we should make sure to change the different docstrings from the file.

Labels: Documentation, help wanted
`min_samples` in HDSCAN

### Describe the issue linked to the documentation

I find the description of the `min_samples` argument in sklearn.cluster.HDBSCAN confusing.

It says "The number of samples in a neighborhood for a point to be considered as a core point. This includes the point itself."

But if I understand everything correctly `min_samples` corresponds to the $k$ used to compute the core distance $\text{core}_k\left(x\right)$ for every sample $x$ where the $k$'th core distance for some sample $x$ is defined as the distance to the $k$'th nearest-neighbor of $x$ (counting itself). (-> which exactly what is happening in the code here: https://github.com/scikit-learn-contrib/hdbscan/blob/fc94241a4ecf5d3668cbe33b36ef03e6160d7ab7/hdbscan/_hdbscan_reachability.pyx#L45-L47, where it is called `min_points`)

I don't understand how both of these descriptions are equivalent. I would assume that other people might find that confusing as well.

Link in Code: https://github.com/scikit-learn/scikit-learn/blob/8721245511de2f225ff5f9aa5f5fadce663cd4a3/sklearn/cluster/_hdbscan/hdbscan.py#L441-L444

Link in Documentation: https://scikit-learn.org/stable/modules/generated/sklearn.cluster.DBSCAN.html#sklearn.cluster.DBSCAN

### Suggest a potential alternative/fix

_No response_

COMMENT:
@glemaitre I opened a draft PR for this. I have a proposal for the description of `min_samples`, if that's fine I can write that also in other place in sklearn/cluster/_hdbscan/hdbscan.py, e.g. here https://github.com/scikit-learn/scikit-learn/blob/dc1cad2b3fddb8b9069d7cfd89cb1039260baf8e/sklearn/cluster/_hdbscan/hdbscan.py#L83-L99

or here

https://github.com/scikit-learn/scikit-learn/blob/dc1cad2b3fddb8b9069d7cfd89cb1039260baf8e/sklearn/cluster/_hdbscan/hdbscan.py#L599-L605

Labels: Documentation, help wanted
Is it intention to drop `check_estimator_sparse_data` in 1.5?

### Describe the bug

While running the 1.5.0 release candidate, my collaborator @FBruzzesi on scikit-lego ran our testing suite and [noticed something breaking](https://github.com/FBruzzesi/scikit-lego/actions/runs/8975596456/job/24650556520). Here's the error message:

```
ImportError while loading conftest '/home/runner/work/scikit-lego/scikit-lego/tests/conftest.py'.
tests/conftest.py:43: in <module>
    estimator_checks.check_estimator_sparse_data,
E   AttributeError: module 'sklearn.utils.estimator_checks' has no attribute 'check_estimator_sparse_data'. Did you mean: 'check_estimator_sparse_array'?
```

Figured I'd ping and check, did a function get renamed? If so, it feels breaking and I can't recall a warning (but I may be mistaken, please tell me if I missed that). This is mostly just a ping issue so folks are aware, feel free to close if this feels like a false alarm. 

### Steps/Code to Reproduce

```python
from sklearn.utils import estimator_checks

estimator_checks.check_estimator_sparse_array
```

### Expected Results

No error is thrown.

### Actual Results

```
AttributeError: module 'sklearn.utils.estimator_checks' has no attribute 'check_estimator_sparse_data'. Did you mean: 'check_estimator_sparse_array'?
```

### Versions

```shell
This is the v1.5rc01
```

COMMENT:
Thanks for the feedback on the RC @koaning !

This check was split into 2 different checks, one for sparse matrices and one for sparse arrays, see https://github.com/scikit-learn/scikit-learn/pull/27576. It's kind of a grey area because all these checks are not really public so we may change them without deprecation. I think it can't hurt to at least mention it in the changelog. Note that there's also ongoing work to refactor these checks to expose a third party developer API for which these considerations will be better defined.

Labels: Documentation, Developer API
Is it intention to drop `check_estimator_sparse_data` in 1.5?

### Describe the bug

While running the 1.5.0 release candidate, my collaborator @FBruzzesi on scikit-lego ran our testing suite and [noticed something breaking](https://github.com/FBruzzesi/scikit-lego/actions/runs/8975596456/job/24650556520). Here's the error message:

```
ImportError while loading conftest '/home/runner/work/scikit-lego/scikit-lego/tests/conftest.py'.
tests/conftest.py:43: in <module>
    estimator_checks.check_estimator_sparse_data,
E   AttributeError: module 'sklearn.utils.estimator_checks' has no attribute 'check_estimator_sparse_data'. Did you mean: 'check_estimator_sparse_array'?
```

Figured I'd ping and check, did a function get renamed? If so, it feels breaking and I can't recall a warning (but I may be mistaken, please tell me if I missed that). This is mostly just a ping issue so folks are aware, feel free to close if this feels like a false alarm. 

### Steps/Code to Reproduce

```python
from sklearn.utils import estimator_checks

estimator_checks.check_estimator_sparse_array
```

### Expected Results

No error is thrown.

### Actual Results

```
AttributeError: module 'sklearn.utils.estimator_checks' has no attribute 'check_estimator_sparse_data'. Did you mean: 'check_estimator_sparse_array'?
```

### Versions

```shell
This is the v1.5rc01
```

COMMENT:
When is something in the public API? I assumed it was public enough because it publicly accessible (no underscore prefix in the function name). I think we'll be fine with making the switch on the sklego side but there may certainly be other 3rd party packages that use this function because you kind of need to use these testing functions if you want to guarantee that you are compatible to the sklearn API.

Labels: Documentation, Developer API
Is it intention to drop `check_estimator_sparse_data` in 1.5?

### Describe the bug

While running the 1.5.0 release candidate, my collaborator @FBruzzesi on scikit-lego ran our testing suite and [noticed something breaking](https://github.com/FBruzzesi/scikit-lego/actions/runs/8975596456/job/24650556520). Here's the error message:

```
ImportError while loading conftest '/home/runner/work/scikit-lego/scikit-lego/tests/conftest.py'.
tests/conftest.py:43: in <module>
    estimator_checks.check_estimator_sparse_data,
E   AttributeError: module 'sklearn.utils.estimator_checks' has no attribute 'check_estimator_sparse_data'. Did you mean: 'check_estimator_sparse_array'?
```

Figured I'd ping and check, did a function get renamed? If so, it feels breaking and I can't recall a warning (but I may be mistaken, please tell me if I missed that). This is mostly just a ping issue so folks are aware, feel free to close if this feels like a false alarm. 

### Steps/Code to Reproduce

```python
from sklearn.utils import estimator_checks

estimator_checks.check_estimator_sparse_array
```

### Expected Results

No error is thrown.

### Actual Results

```
AttributeError: module 'sklearn.utils.estimator_checks' has no attribute 'check_estimator_sparse_data'. Did you mean: 'check_estimator_sparse_array'?
```

### Versions

```shell
This is the v1.5rc01
```

COMMENT:
Agree with Jeremie about it being a gray area.

I think we should follow the normal deprecation policy if we change something related to testing estimators that is directly mentioned in the documentation https://scikit-learn.org/dev/developers/develop.html#rolling-your-own-estimator (Maybe another thing to remember is when we change the checks so that estimators that used to pass suddenly fail)

However the individual checks, what they are called and what they do is probably an "implementation detail". 

So I think we should make sure that we steer people towards using things that we want them to use, and away from the other stuff.

Labels: Documentation, Developer API
Is it intention to drop `check_estimator_sparse_data` in 1.5?

### Describe the bug

While running the 1.5.0 release candidate, my collaborator @FBruzzesi on scikit-lego ran our testing suite and [noticed something breaking](https://github.com/FBruzzesi/scikit-lego/actions/runs/8975596456/job/24650556520). Here's the error message:

```
ImportError while loading conftest '/home/runner/work/scikit-lego/scikit-lego/tests/conftest.py'.
tests/conftest.py:43: in <module>
    estimator_checks.check_estimator_sparse_data,
E   AttributeError: module 'sklearn.utils.estimator_checks' has no attribute 'check_estimator_sparse_data'. Did you mean: 'check_estimator_sparse_array'?
```

Figured I'd ping and check, did a function get renamed? If so, it feels breaking and I can't recall a warning (but I may be mistaken, please tell me if I missed that). This is mostly just a ping issue so folks are aware, feel free to close if this feels like a false alarm. 

### Steps/Code to Reproduce

```python
from sklearn.utils import estimator_checks

estimator_checks.check_estimator_sparse_array
```

### Expected Results

No error is thrown.

### Actual Results

```
AttributeError: module 'sklearn.utils.estimator_checks' has no attribute 'check_estimator_sparse_data'. Did you mean: 'check_estimator_sparse_array'?
```

### Versions

```shell
This is the v1.5rc01
```

COMMENT:
*to me*, the official public API is what is officially documented, i.e. in ``classes.rst``. ``check_estimator`` is, but individual checks are not. I'd like however to have a third category, developer API, in between the current public/private API. One of its goal is to better define what checks are required to make an estimator scikit-learn compatible, because we are aware that the current ``check_estimator`` is too strict (see https://github.com/scikit-learn/scikit-learn/issues/13969, https://github.com/scikit-learn/scikit-learn/issues/16241).

Labels: Documentation, Developer API
Is it intention to drop `check_estimator_sparse_data` in 1.5?

### Describe the bug

While running the 1.5.0 release candidate, my collaborator @FBruzzesi on scikit-lego ran our testing suite and [noticed something breaking](https://github.com/FBruzzesi/scikit-lego/actions/runs/8975596456/job/24650556520). Here's the error message:

```
ImportError while loading conftest '/home/runner/work/scikit-lego/scikit-lego/tests/conftest.py'.
tests/conftest.py:43: in <module>
    estimator_checks.check_estimator_sparse_data,
E   AttributeError: module 'sklearn.utils.estimator_checks' has no attribute 'check_estimator_sparse_data'. Did you mean: 'check_estimator_sparse_array'?
```

Figured I'd ping and check, did a function get renamed? If so, it feels breaking and I can't recall a warning (but I may be mistaken, please tell me if I missed that). This is mostly just a ping issue so folks are aware, feel free to close if this feels like a false alarm. 

### Steps/Code to Reproduce

```python
from sklearn.utils import estimator_checks

estimator_checks.check_estimator_sparse_array
```

### Expected Results

No error is thrown.

### Actual Results

```
AttributeError: module 'sklearn.utils.estimator_checks' has no attribute 'check_estimator_sparse_data'. Did you mean: 'check_estimator_sparse_array'?
```

### Versions

```shell
This is the v1.5rc01
```

COMMENT:
Fair enough, the tests in scikit-lego are pretty old (>6 years) so it could be perfectly fine/normal for us to revamp it. The only small warning is that there may be a fair amount of other plugin packages who are going to notice, but if this is mentioned in the release notes that should suffice.

Labels: Documentation, Developer API
Is it intention to drop `check_estimator_sparse_data` in 1.5?

### Describe the bug

While running the 1.5.0 release candidate, my collaborator @FBruzzesi on scikit-lego ran our testing suite and [noticed something breaking](https://github.com/FBruzzesi/scikit-lego/actions/runs/8975596456/job/24650556520). Here's the error message:

```
ImportError while loading conftest '/home/runner/work/scikit-lego/scikit-lego/tests/conftest.py'.
tests/conftest.py:43: in <module>
    estimator_checks.check_estimator_sparse_data,
E   AttributeError: module 'sklearn.utils.estimator_checks' has no attribute 'check_estimator_sparse_data'. Did you mean: 'check_estimator_sparse_array'?
```

Figured I'd ping and check, did a function get renamed? If so, it feels breaking and I can't recall a warning (but I may be mistaken, please tell me if I missed that). This is mostly just a ping issue so folks are aware, feel free to close if this feels like a false alarm. 

### Steps/Code to Reproduce

```python
from sklearn.utils import estimator_checks

estimator_checks.check_estimator_sparse_array
```

### Expected Results

No error is thrown.

### Actual Results

```
AttributeError: module 'sklearn.utils.estimator_checks' has no attribute 'check_estimator_sparse_data'. Did you mean: 'check_estimator_sparse_array'?
```

### Versions

```shell
This is the v1.5rc01
```

COMMENT:
We certainly need to have a _public_ set of tests for third party developers. It's along the lines of what @glemaitre has been working on.

Labels: Documentation, Developer API
Base function to check if the model is a clusterer (analogous to `base.is_classifier()` and `base.is_regressor()`)?

### Discussed in https://github.com/scikit-learn/scikit-learn/discussions/28904

<div type='discussions-op-text'>

<sup>Originally posted by **aoot** April 26, 2024</sup>
According to [the note on figuring out the model type](https://scikit-learn.org/stable/developers/develop.html#estimator-types), it is recommended to use `sklearn.base.is_classifier()` or `sklearn.base.is_regressor()` function to check instead of of checking the attribute `_estimator_type` directly.

However, since the attribute `_estimator_type` can be either `"classifier"`, `"regressor"`, and `"clusterer"`, are there any base function such as `sklearn.base.is_clusterer()` to check if the model is a clusterer?

Thanks for your input!</div>

https://github.com/scikit-learn/scikit-learn/pull/28936 is an effort to fix this. Not sure what to think of it.

COMMENT:
It makes sense and in the same time I'm not sure if we want to move in that direction
- there are more types of estimators (decomposition, outlier detectors, density estimators, ...). Do we want to do it for these as well ?
- I thought that at some point we wanted to deprecate estimator_type if favor of tags. Is it still the case (I think we should) ?

Labels: New Feature
Base function to check if the model is a clusterer (analogous to `base.is_classifier()` and `base.is_regressor()`)?

### Discussed in https://github.com/scikit-learn/scikit-learn/discussions/28904

<div type='discussions-op-text'>

<sup>Originally posted by **aoot** April 26, 2024</sup>
According to [the note on figuring out the model type](https://scikit-learn.org/stable/developers/develop.html#estimator-types), it is recommended to use `sklearn.base.is_classifier()` or `sklearn.base.is_regressor()` function to check instead of of checking the attribute `_estimator_type` directly.

However, since the attribute `_estimator_type` can be either `"classifier"`, `"regressor"`, and `"clusterer"`, are there any base function such as `sklearn.base.is_clusterer()` to check if the model is a clusterer?

Thanks for your input!</div>

https://github.com/scikit-learn/scikit-learn/pull/28936 is an effort to fix this. Not sure what to think of it.

COMMENT:
I don't mind deprecating `_estimator_type` and adding it to tags. But that's independent of having a helper function to check if an estimator is a classifier, regressor, or a clusterer. I think we don't have to cover all cases with these helper functions. We only need the ones most commonly used.

Labels: New Feature
Base function to check if the model is a clusterer (analogous to `base.is_classifier()` and `base.is_regressor()`)?

### Discussed in https://github.com/scikit-learn/scikit-learn/discussions/28904

<div type='discussions-op-text'>

<sup>Originally posted by **aoot** April 26, 2024</sup>
According to [the note on figuring out the model type](https://scikit-learn.org/stable/developers/develop.html#estimator-types), it is recommended to use `sklearn.base.is_classifier()` or `sklearn.base.is_regressor()` function to check instead of of checking the attribute `_estimator_type` directly.

However, since the attribute `_estimator_type` can be either `"classifier"`, `"regressor"`, and `"clusterer"`, are there any base function such as `sklearn.base.is_clusterer()` to check if the model is a clusterer?

Thanks for your input!</div>

https://github.com/scikit-learn/scikit-learn/pull/28936 is an effort to fix this. Not sure what to think of it.

COMMENT:
For the estimator types not so commonly used, one could imagine a more generic function like
```python
def is_estimator_type(estimator, expected_type: str):
    return getattr(estimator, "_estimator_type", None) == expected_type
```
in order to check for a given category.

Labels: New Feature
Base function to check if the model is a clusterer (analogous to `base.is_classifier()` and `base.is_regressor()`)?

### Discussed in https://github.com/scikit-learn/scikit-learn/discussions/28904

<div type='discussions-op-text'>

<sup>Originally posted by **aoot** April 26, 2024</sup>
According to [the note on figuring out the model type](https://scikit-learn.org/stable/developers/develop.html#estimator-types), it is recommended to use `sklearn.base.is_classifier()` or `sklearn.base.is_regressor()` function to check instead of of checking the attribute `_estimator_type` directly.

However, since the attribute `_estimator_type` can be either `"classifier"`, `"regressor"`, and `"clusterer"`, are there any base function such as `sklearn.base.is_clusterer()` to check if the model is a clusterer?

Thanks for your input!</div>

https://github.com/scikit-learn/scikit-learn/pull/28936 is an effort to fix this. Not sure what to think of it.

COMMENT:
What we're planning to do would be more like:

```py
get_tags(estimator)["estimator_type"] == expected_type
```

Labels: New Feature