Talip7/scikit-learn-issues-multilabel huggingface dataset:
DIS: Cython 3 perf regressions

It looks like scikit-learn hasn't updated to Cython 3 yet, but when you do, can you keep an eye out for performance regressions?

On pandas, we updated to Cython 3 but then reverted, since we had issues with some of our benchmarks regressing, and it would be nice to know if this is a bigger problem in Cython.

COMMENT:
@da-woods looks like https://github.com/cython/cython/pull/5678 improved things a bit but not entirely. I ran the same profile with the master branch of cython:

![Screenshot_cy_master](https://github.com/scikit-learn/scikit-learn/assets/34657725/be135974-01bb-4cd7-8cb4-c0252f8b27eb)

The gil issue at the end of `_splitter_node_split_best` has gone away (circled in blue on the right of previous profile) but it's still here for `ClassificationCriterion_update` (circled in blue on the left of previous profile). 

> It might go away if you used sample_indices and sample_weights from the class rather than assigning them to local variables.

I'm going to try that, thanks for looking into it.
EDIT: I tried and it didn't change anything :/

Labels: Performance, Needs Benchmarks, cython
DIS: Cython 3 perf regressions

It looks like scikit-learn hasn't updated to Cython 3 yet, but when you do, can you keep an eye out for performance regressions?

On pandas, we updated to Cython 3 but then reverted, since we had issues with some of our benchmarks regressing, and it would be nice to know if this is a bigger problem in Cython.

COMMENT:
Here's the annotated version of this function if it can help (with cython master):
![Screenshot_annotate](https://github.com/scikit-learn/scikit-learn/assets/34657725/63228543-64b7-477e-8bad-90bff18eabfa)

Labels: Performance, Needs Benchmarks, cython
DIS: Cython 3 perf regressions

It looks like scikit-learn hasn't updated to Cython 3 yet, but when you do, can you keep an eye out for performance regressions?

On pandas, we updated to Cython 3 but then reverted, since we had issues with some of our benchmarks regressing, and it would be nice to know if this is a bigger problem in Cython.

COMMENT:
That does look helpful thanks. There's two related problems:
1. Refnanny only applies to Cython's internal testing, so getting the GIL to set it up should be conditionally compiled.
2. I don't think we need refnanny at all here.

I'll try to fix it in the next couple of days

Labels: Performance, Needs Benchmarks, cython
DIS: Cython 3 perf regressions

It looks like scikit-learn hasn't updated to Cython 3 yet, but when you do, can you keep an eye out for performance regressions?

On pandas, we updated to Cython 3 but then reverted, since we had issues with some of our benchmarks regressing, and it would be nice to know if this is a bigger problem in Cython.

COMMENT:
Fix committed, will be resolved in Cython 3.0.3.

Labels: Performance, Needs Benchmarks, cython
DIS: Cython 3 perf regressions

It looks like scikit-learn hasn't updated to Cython 3 yet, but when you do, can you keep an eye out for performance regressions?

On pandas, we updated to Cython 3 but then reverted, since we had issues with some of our benchmarks regressing, and it would be nice to know if this is a bigger problem in Cython.

COMMENT:
Good news, I ran some benchmarks regarding the estimators for which we identified slowdowns coming from cython 3 (`RandomForest*`, `(Hist)GradientBoosting*`, `KNeighbors*`) against the latest cython master and they're all as fast as they were with cython 0.29.36 (sometimes even a little bit faster) !

It should be confirmed in the asv benchmarks when we update them to run against cython 3.0.3 (when it's released)

Labels: Performance, Needs Benchmarks, cython
DIS: Cython 3 perf regressions

It looks like scikit-learn hasn't updated to Cython 3 yet, but when you do, can you keep an eye out for performance regressions?

On pandas, we updated to Cython 3 but then reverted, since we had issues with some of our benchmarks regressing, and it would be nice to know if this is a bigger problem in Cython.

COMMENT:
Thanks a bunch @scoder @da-woods for taking care about this issue.

Labels: Performance, Needs Benchmarks, cython
DIS: Cython 3 perf regressions

It looks like scikit-learn hasn't updated to Cython 3 yet, but when you do, can you keep an eye out for performance regressions?

On pandas, we updated to Cython 3 but then reverted, since we had issues with some of our benchmarks regressing, and it would be nice to know if this is a bigger problem in Cython.

COMMENT:
Can we close?
Has someone the link to our benchmark results?

Labels: Performance, Needs Benchmarks, cython
DIS: Cython 3 perf regressions

It looks like scikit-learn hasn't updated to Cython 3 yet, but when you do, can you keep an eye out for performance regressions?

On pandas, we updated to Cython 3 but then reverted, since we had issues with some of our benchmarks regressing, and it would be nice to know if this is a bigger problem in Cython.

COMMENT:
@jeremiedbb merged added Cython 3.0.3 in the ASV benchmark. We should be able to check that we don't have remaining regressions.

Labels: Performance, Needs Benchmarks, cython
DIS: Cython 3 perf regressions

It looks like scikit-learn hasn't updated to Cython 3 yet, but when you do, can you keep an eye out for performance regressions?

On pandas, we updated to Cython 3 but then reverted, since we had issues with some of our benchmarks regressing, and it would be nice to know if this is a bigger problem in Cython.

COMMENT:
I had a look at https://scikit-learn.org/scikit-learn-benchmarks/#regressions?sort=3&dir=desc and the last commits are still from early September, so the upload of the results does not seem to work and does not allow to conclude if the Cython regressions have been fixed in 3.0.3.

Labels: Performance, Needs Benchmarks, cython
DIS: Cython 3 perf regressions

It looks like scikit-learn hasn't updated to Cython 3 yet, but when you do, can you keep an eye out for performance regressions?

On pandas, we updated to Cython 3 but then reverted, since we had issues with some of our benchmarks regressing, and it would be nice to know if this is a bigger problem in Cython.

COMMENT:
Actually the results are uploaded, see: https://github.com/scikit-learn/scikit-learn-benchmarks/commits/master . However the plots do not show them...

Labels: Performance, Needs Benchmarks, cython
BisectingKMeans floating point exception fatal error on OSX

### Describe the bug

Hi, thanks for this fantastic library 🚀 🎉 

I believe I found a bug. In the BisectingKMeans clustering, the `predict` function cannot be used when the to-be-predicted-data is on a different numerical scale than the fitted data. Other clustering methods like e.g., KMeans dont have this problem.

In the example below, I fitted the BisectingKMeans on random data and then multiplied the data that should be predicted by 50. It causes a floating point exception error which is pretty bad because python silently exits.

### Steps/Code to Reproduce

```py
from sklearn.cluster import BisectingKMeans, KMeans
import numpy as np
x = np.random.rand(3000, 10)

bisect_means = BisectingKMeans(n_clusters=10).fit(x)

labels = bisect_means.predict(50*np.random.rand(100, 10))
print(labels)
```

### Expected Results

A list of predicted class labels

### Actual Results

Python silently exits with:
```
[1]    45074 floating point exception  python foo.py
```
In Jupyter/ipython the kernel simply dies.

### Versions

```shell
System:
    python: 3.9.16 (main, Mar  8 2023, 04:29:44)  [Clang 14.0.6 ]
executable: /Users/jab/miniconda3/envs/qondot/bin/python
   machine: macOS-10.16-x86_64-i386-64bit

Python dependencies:
      sklearn: 1.3.0
          pip: 23.0.1
   setuptools: 67.8.0
        numpy: 1.21.6
        scipy: 1.10.1
       Cython: 0.29.35
       pandas: 1.5.3
   matplotlib: 3.7.1
       joblib: 1.2.0
threadpoolctl: 3.1.0

Built with OpenMP: True

threadpoolctl info:
       user_api: openmp
   internal_api: openmp
         prefix: libomp
       filepath: /Users/jab/miniconda3/envs/qondot/lib/python3.9/site-packages/sklearn/.dylibs/libomp.dylib
        version: None
    num_threads: 8

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /Users/jab/miniconda3/envs/qondot/lib/python3.9/site-packages/numpy/.dylibs/libopenblas.0.dylib
        version: 0.3.17
threading_layer: pthreads
   architecture: Haswell
    num_threads: 4

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /Users/jab/miniconda3/envs/qondot/lib/python3.9/site-packages/scipy/.dylibs/libopenblas.0.dylib
        version: 0.3.18
threading_layer: pthreads
   architecture: SkylakeX
    num_threads: 4
```

COMMENT:
This is unexpected and is likely to be something specific to your machine being a MacOS or your environment.

One thing I noticed in your versions is that you have a different OpenBLAS version from numpy and scipy. Could it be the issue, hard to tell.

Could you follow the instructions from https://github.com/scikit-learn/scikit-learn/issues/23574#issuecomment-1248963822 and report back.

Labels: Bug, Needs Triage
BisectingKMeans floating point exception fatal error on OSX

### Describe the bug

Hi, thanks for this fantastic library 🚀 🎉 

I believe I found a bug. In the BisectingKMeans clustering, the `predict` function cannot be used when the to-be-predicted-data is on a different numerical scale than the fitted data. Other clustering methods like e.g., KMeans dont have this problem.

In the example below, I fitted the BisectingKMeans on random data and then multiplied the data that should be predicted by 50. It causes a floating point exception error which is pretty bad because python silently exits.

### Steps/Code to Reproduce

```py
from sklearn.cluster import BisectingKMeans, KMeans
import numpy as np
x = np.random.rand(3000, 10)

bisect_means = BisectingKMeans(n_clusters=10).fit(x)

labels = bisect_means.predict(50*np.random.rand(100, 10))
print(labels)
```

### Expected Results

A list of predicted class labels

### Actual Results

Python silently exits with:
```
[1]    45074 floating point exception  python foo.py
```
In Jupyter/ipython the kernel simply dies.

### Versions

```shell
System:
    python: 3.9.16 (main, Mar  8 2023, 04:29:44)  [Clang 14.0.6 ]
executable: /Users/jab/miniconda3/envs/qondot/bin/python
   machine: macOS-10.16-x86_64-i386-64bit

Python dependencies:
      sklearn: 1.3.0
          pip: 23.0.1
   setuptools: 67.8.0
        numpy: 1.21.6
        scipy: 1.10.1
       Cython: 0.29.35
       pandas: 1.5.3
   matplotlib: 3.7.1
       joblib: 1.2.0
threadpoolctl: 3.1.0

Built with OpenMP: True

threadpoolctl info:
       user_api: openmp
   internal_api: openmp
         prefix: libomp
       filepath: /Users/jab/miniconda3/envs/qondot/lib/python3.9/site-packages/sklearn/.dylibs/libomp.dylib
        version: None
    num_threads: 8

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /Users/jab/miniconda3/envs/qondot/lib/python3.9/site-packages/numpy/.dylibs/libopenblas.0.dylib
        version: 0.3.17
threading_layer: pthreads
   architecture: Haswell
    num_threads: 4

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /Users/jab/miniconda3/envs/qondot/lib/python3.9/site-packages/scipy/.dylibs/libopenblas.0.dylib
        version: 0.3.18
threading_layer: pthreads
   architecture: SkylakeX
    num_threads: 4
```

COMMENT:
Could you please try to reproduce by installing everything (numpy / scipy / scikit-learn / openblas) from conda-forge?

```
conda create -n debug-env -c conda-forge scikit-learn
conda activate debug-env
python repro_script.py
```

if you can reproduce their, I would also be interested in the output of `conda list` and `sklearn.show_versions()`.

EDIT: added the missing `-c conda-forge`.

Labels: Bug, Needs Triage
BisectingKMeans floating point exception fatal error on OSX

### Describe the bug

Hi, thanks for this fantastic library 🚀 🎉 

I believe I found a bug. In the BisectingKMeans clustering, the `predict` function cannot be used when the to-be-predicted-data is on a different numerical scale than the fitted data. Other clustering methods like e.g., KMeans dont have this problem.

In the example below, I fitted the BisectingKMeans on random data and then multiplied the data that should be predicted by 50. It causes a floating point exception error which is pretty bad because python silently exits.

### Steps/Code to Reproduce

```py
from sklearn.cluster import BisectingKMeans, KMeans
import numpy as np
x = np.random.rand(3000, 10)

bisect_means = BisectingKMeans(n_clusters=10).fit(x)

labels = bisect_means.predict(50*np.random.rand(100, 10))
print(labels)
```

### Expected Results

A list of predicted class labels

### Actual Results

Python silently exits with:
```
[1]    45074 floating point exception  python foo.py
```
In Jupyter/ipython the kernel simply dies.

### Versions

```shell
System:
    python: 3.9.16 (main, Mar  8 2023, 04:29:44)  [Clang 14.0.6 ]
executable: /Users/jab/miniconda3/envs/qondot/bin/python
   machine: macOS-10.16-x86_64-i386-64bit

Python dependencies:
      sklearn: 1.3.0
          pip: 23.0.1
   setuptools: 67.8.0
        numpy: 1.21.6
        scipy: 1.10.1
       Cython: 0.29.35
       pandas: 1.5.3
   matplotlib: 3.7.1
       joblib: 1.2.0
threadpoolctl: 3.1.0

Built with OpenMP: True

threadpoolctl info:
       user_api: openmp
   internal_api: openmp
         prefix: libomp
       filepath: /Users/jab/miniconda3/envs/qondot/lib/python3.9/site-packages/sklearn/.dylibs/libomp.dylib
        version: None
    num_threads: 8

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /Users/jab/miniconda3/envs/qondot/lib/python3.9/site-packages/numpy/.dylibs/libopenblas.0.dylib
        version: 0.3.17
threading_layer: pthreads
   architecture: Haswell
    num_threads: 4

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /Users/jab/miniconda3/envs/qondot/lib/python3.9/site-packages/scipy/.dylibs/libopenblas.0.dylib
        version: 0.3.18
threading_layer: pthreads
   architecture: SkylakeX
    num_threads: 4
```

COMMENT:
Thanks. This is really strange. I am also on a mac, albeit M1,  and I cannot reproduce, neither when install from conda-forge or pypi.org...

Labels: Bug, Needs Triage
BisectingKMeans floating point exception fatal error on OSX

### Describe the bug

Hi, thanks for this fantastic library 🚀 🎉 

I believe I found a bug. In the BisectingKMeans clustering, the `predict` function cannot be used when the to-be-predicted-data is on a different numerical scale than the fitted data. Other clustering methods like e.g., KMeans dont have this problem.

In the example below, I fitted the BisectingKMeans on random data and then multiplied the data that should be predicted by 50. It causes a floating point exception error which is pretty bad because python silently exits.

### Steps/Code to Reproduce

```py
from sklearn.cluster import BisectingKMeans, KMeans
import numpy as np
x = np.random.rand(3000, 10)

bisect_means = BisectingKMeans(n_clusters=10).fit(x)

labels = bisect_means.predict(50*np.random.rand(100, 10))
print(labels)
```

### Expected Results

A list of predicted class labels

### Actual Results

Python silently exits with:
```
[1]    45074 floating point exception  python foo.py
```
In Jupyter/ipython the kernel simply dies.

### Versions

```shell
System:
    python: 3.9.16 (main, Mar  8 2023, 04:29:44)  [Clang 14.0.6 ]
executable: /Users/jab/miniconda3/envs/qondot/bin/python
   machine: macOS-10.16-x86_64-i386-64bit

Python dependencies:
      sklearn: 1.3.0
          pip: 23.0.1
   setuptools: 67.8.0
        numpy: 1.21.6
        scipy: 1.10.1
       Cython: 0.29.35
       pandas: 1.5.3
   matplotlib: 3.7.1
       joblib: 1.2.0
threadpoolctl: 3.1.0

Built with OpenMP: True

threadpoolctl info:
       user_api: openmp
   internal_api: openmp
         prefix: libomp
       filepath: /Users/jab/miniconda3/envs/qondot/lib/python3.9/site-packages/sklearn/.dylibs/libomp.dylib
        version: None
    num_threads: 8

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /Users/jab/miniconda3/envs/qondot/lib/python3.9/site-packages/numpy/.dylibs/libopenblas.0.dylib
        version: 0.3.17
threading_layer: pthreads
   architecture: Haswell
    num_threads: 4

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /Users/jab/miniconda3/envs/qondot/lib/python3.9/site-packages/scipy/.dylibs/libopenblas.0.dylib
        version: 0.3.18
threading_layer: pthreads
   architecture: SkylakeX
    num_threads: 4
```

COMMENT:
Have you tried increasing the scaling factor to a higher number?

My example uses `50`:
```py
labels = bisect_means.predict(50*np.random.rand(100, 10))
```

When I set it to 5, the error occurs only sometimes, so generally higher values seem more problematic.

Labels: Bug, Needs Triage
BisectingKMeans floating point exception fatal error on OSX

### Describe the bug

Hi, thanks for this fantastic library 🚀 🎉 

I believe I found a bug. In the BisectingKMeans clustering, the `predict` function cannot be used when the to-be-predicted-data is on a different numerical scale than the fitted data. Other clustering methods like e.g., KMeans dont have this problem.

In the example below, I fitted the BisectingKMeans on random data and then multiplied the data that should be predicted by 50. It causes a floating point exception error which is pretty bad because python silently exits.

### Steps/Code to Reproduce

```py
from sklearn.cluster import BisectingKMeans, KMeans
import numpy as np
x = np.random.rand(3000, 10)

bisect_means = BisectingKMeans(n_clusters=10).fit(x)

labels = bisect_means.predict(50*np.random.rand(100, 10))
print(labels)
```

### Expected Results

A list of predicted class labels

### Actual Results

Python silently exits with:
```
[1]    45074 floating point exception  python foo.py
```
In Jupyter/ipython the kernel simply dies.

### Versions

```shell
System:
    python: 3.9.16 (main, Mar  8 2023, 04:29:44)  [Clang 14.0.6 ]
executable: /Users/jab/miniconda3/envs/qondot/bin/python
   machine: macOS-10.16-x86_64-i386-64bit

Python dependencies:
      sklearn: 1.3.0
          pip: 23.0.1
   setuptools: 67.8.0
        numpy: 1.21.6
        scipy: 1.10.1
       Cython: 0.29.35
       pandas: 1.5.3
   matplotlib: 3.7.1
       joblib: 1.2.0
threadpoolctl: 3.1.0

Built with OpenMP: True

threadpoolctl info:
       user_api: openmp
   internal_api: openmp
         prefix: libomp
       filepath: /Users/jab/miniconda3/envs/qondot/lib/python3.9/site-packages/sklearn/.dylibs/libomp.dylib
        version: None
    num_threads: 8

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /Users/jab/miniconda3/envs/qondot/lib/python3.9/site-packages/numpy/.dylibs/libopenblas.0.dylib
        version: 0.3.17
threading_layer: pthreads
   architecture: Haswell
    num_threads: 4

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /Users/jab/miniconda3/envs/qondot/lib/python3.9/site-packages/scipy/.dylibs/libopenblas.0.dylib
        version: 0.3.18
threading_layer: pthreads
   architecture: SkylakeX
    num_threads: 4
```

COMMENT:
I noticed that I forgot the `-c conda-forge` in the env creation command of https://github.com/scikit-learn/scikit-learn/issues/27081#issuecomment-1693287454. Can you please try again? The conda list output shows you are using everything from the anaconda defaults channel.

Labels: Bug, Needs Triage
BisectingKMeans floating point exception fatal error on OSX

### Describe the bug

Hi, thanks for this fantastic library 🚀 🎉 

I believe I found a bug. In the BisectingKMeans clustering, the `predict` function cannot be used when the to-be-predicted-data is on a different numerical scale than the fitted data. Other clustering methods like e.g., KMeans dont have this problem.

In the example below, I fitted the BisectingKMeans on random data and then multiplied the data that should be predicted by 50. It causes a floating point exception error which is pretty bad because python silently exits.

### Steps/Code to Reproduce

```py
from sklearn.cluster import BisectingKMeans, KMeans
import numpy as np
x = np.random.rand(3000, 10)

bisect_means = BisectingKMeans(n_clusters=10).fit(x)

labels = bisect_means.predict(50*np.random.rand(100, 10))
print(labels)
```

### Expected Results

A list of predicted class labels

### Actual Results

Python silently exits with:
```
[1]    45074 floating point exception  python foo.py
```
In Jupyter/ipython the kernel simply dies.

### Versions

```shell
System:
    python: 3.9.16 (main, Mar  8 2023, 04:29:44)  [Clang 14.0.6 ]
executable: /Users/jab/miniconda3/envs/qondot/bin/python
   machine: macOS-10.16-x86_64-i386-64bit

Python dependencies:
      sklearn: 1.3.0
          pip: 23.0.1
   setuptools: 67.8.0
        numpy: 1.21.6
        scipy: 1.10.1
       Cython: 0.29.35
       pandas: 1.5.3
   matplotlib: 3.7.1
       joblib: 1.2.0
threadpoolctl: 3.1.0

Built with OpenMP: True

threadpoolctl info:
       user_api: openmp
   internal_api: openmp
         prefix: libomp
       filepath: /Users/jab/miniconda3/envs/qondot/lib/python3.9/site-packages/sklearn/.dylibs/libomp.dylib
        version: None
    num_threads: 8

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /Users/jab/miniconda3/envs/qondot/lib/python3.9/site-packages/numpy/.dylibs/libopenblas.0.dylib
        version: 0.3.17
threading_layer: pthreads
   architecture: Haswell
    num_threads: 4

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /Users/jab/miniconda3/envs/qondot/lib/python3.9/site-packages/scipy/.dylibs/libopenblas.0.dylib
        version: 0.3.18
threading_layer: pthreads
   architecture: SkylakeX
    num_threads: 4
```

COMMENT:
Also if `gdb` does not work, maybe you can try with `lldb`:

```
$ lldb -- python repro_script.py
...
(lldb) run
...
(lldb) bt
```

Labels: Bug, Needs Triage