Talip7/scikit-learn-issues-multilabel huggingface dataset:
Segmentation Fault in KMeans on OSX

### Describe the bug

Hi when I run this code

```
import numpy as np      
from sklearn.cluster import KMeans

X_train = np.random.RandomState(0).random((10, 2))
kmeans = KMeans(n_clusters=3, random_state=0).fit(X_train)
```

EDIT by @ogrisel: inserted `.RandomState(0)` in the above snippet to make the reproducer deterministic.

I get this error

`zsh: segmentation fault  python debugging.py`

This can't be a memory error, it's only a 10x2 matrix, any idea what's wrong?

Python 3.10.4
Anaconda installation
>>> sklearn.__version__
'1.0.2'
>>> numpy.__version__
'1.22.3'


### Steps/Code to Reproduce


```
import numpy as np      
from sklearn.cluster import KMeans

X_train = np.random.random((10, 2))
kmeans = KMeans(n_clusters=3, random_state=0).fit(X_train)
```

### Expected Results

KMeans clusters

### Actual Results

`zsh: segmentation fault  python debugging.py`

This can't be a memory error, it's only a 10x2 matrix, any idea what's wrong?


### Versions

```shell
Python 3.10.4
Anaconda installation
>>> sklearn.__version__
'1.0.2'
>>> numpy.__version__
'1.22.3'
```

COMMENT:
@ogrisel , I'm still facing this issue with the latest version of `scikit-learn`. Running the snippet from https://github.com/scikit-learn/scikit-learn/issues/23574#issue-1266371392 results in the segmentation fault. Here's the `environment.yaml` to reproduce:

```yaml
name: test-env
channels:
  - defaults
dependencies:
  - python=3.10
  - conda-forge::scikit-learn==1.3.2
```

And here's the output of `import sklearn; sklearn.show_versions()`:

```
System:
    python: 3.10.13 (main, Sep 11 2023, 08:39:02) [Clang 14.0.6 ]
executable: /Users/alinacherkas/anaconda3/envs/test-env/bin/python
   machine: macOS-10.16-x86_64-i386-64bit

Python dependencies:
      sklearn: 1.3.2
          pip: 23.3
   setuptools: 68.0.0
        numpy: 1.26.0
        scipy: 1.11.3
       Cython: None
       pandas: None
   matplotlib: None
       joblib: 1.2.0
threadpoolctl: 2.2.0

Built with OpenMP: True

threadpoolctl info:
       filepath: /Users/alinacherkas/anaconda3/envs/test-env/lib/libmkl_rt.2.dylib
         prefix: libmkl_rt
       user_api: blas
   internal_api: mkl
        version: 2023.1-Product
    num_threads: 4
threading_layer: intel

       filepath: /Users/alinacherkas/anaconda3/envs/test-env/lib/libiomp5.dylib
         prefix: libiomp
       user_api: openmp
   internal_api: openmp
        version: None
    num_threads: 8

       filepath: /Users/alinacherkas/anaconda3/envs/test-env/lib/libomp.dylib
         prefix: libomp
       user_api: openmp
   internal_api: openmp
        version: None
    num_threads: 8
```

Labels: Bug, Documentation, help wanted, module:cluster, OS:macOS
Segmentation Fault in KMeans on OSX

### Describe the bug

Hi when I run this code

```
import numpy as np      
from sklearn.cluster import KMeans

X_train = np.random.RandomState(0).random((10, 2))
kmeans = KMeans(n_clusters=3, random_state=0).fit(X_train)
```

EDIT by @ogrisel: inserted `.RandomState(0)` in the above snippet to make the reproducer deterministic.

I get this error

`zsh: segmentation fault  python debugging.py`

This can't be a memory error, it's only a 10x2 matrix, any idea what's wrong?

Python 3.10.4
Anaconda installation
>>> sklearn.__version__
'1.0.2'
>>> numpy.__version__
'1.22.3'


### Steps/Code to Reproduce


```
import numpy as np      
from sklearn.cluster import KMeans

X_train = np.random.random((10, 2))
kmeans = KMeans(n_clusters=3, random_state=0).fit(X_train)
```

### Expected Results

KMeans clusters

### Actual Results

`zsh: segmentation fault  python debugging.py`

This can't be a memory error, it's only a 10x2 matrix, any idea what's wrong?


### Versions

```shell
Python 3.10.4
Anaconda installation
>>> sklearn.__version__
'1.0.2'
>>> numpy.__version__
'1.22.3'
```

COMMENT:
Thanks for the report. Indeed, this configuration is known to crash. The llvm libomp and the intel libiomp are known to cause a crash when installed together: either install all numpy, scipy, scikit-learn from the defaults channel (and you should only get libiomp) or install everything from the conda-forge channel (and you should get libomp alone).

Labels: Bug, Documentation, help wanted, module:cluster, OS:macOS
Segmentation Fault in KMeans on OSX

### Describe the bug

Hi when I run this code

```
import numpy as np      
from sklearn.cluster import KMeans

X_train = np.random.RandomState(0).random((10, 2))
kmeans = KMeans(n_clusters=3, random_state=0).fit(X_train)
```

EDIT by @ogrisel: inserted `.RandomState(0)` in the above snippet to make the reproducer deterministic.

I get this error

`zsh: segmentation fault  python debugging.py`

This can't be a memory error, it's only a 10x2 matrix, any idea what's wrong?

Python 3.10.4
Anaconda installation
>>> sklearn.__version__
'1.0.2'
>>> numpy.__version__
'1.22.3'


### Steps/Code to Reproduce


```
import numpy as np      
from sklearn.cluster import KMeans

X_train = np.random.random((10, 2))
kmeans = KMeans(n_clusters=3, random_state=0).fit(X_train)
```

### Expected Results

KMeans clusters

### Actual Results

`zsh: segmentation fault  python debugging.py`

This can't be a memory error, it's only a 10x2 matrix, any idea what's wrong?


### Versions

```shell
Python 3.10.4
Anaconda installation
>>> sklearn.__version__
'1.0.2'
>>> numpy.__version__
'1.22.3'
```

COMMENT:
People in the situation described by @ogrisel might be interested in reading [those notes from `threadpoolctl`](https://github.com/joblib/threadpoolctl/blob/master/multiple_openmp.md).

Labels: Bug, Documentation, help wanted, module:cluster, OS:macOS
Segmentation Fault in KMeans on OSX

### Describe the bug

Hi when I run this code

```
import numpy as np      
from sklearn.cluster import KMeans

X_train = np.random.RandomState(0).random((10, 2))
kmeans = KMeans(n_clusters=3, random_state=0).fit(X_train)
```

EDIT by @ogrisel: inserted `.RandomState(0)` in the above snippet to make the reproducer deterministic.

I get this error

`zsh: segmentation fault  python debugging.py`

This can't be a memory error, it's only a 10x2 matrix, any idea what's wrong?

Python 3.10.4
Anaconda installation
>>> sklearn.__version__
'1.0.2'
>>> numpy.__version__
'1.22.3'


### Steps/Code to Reproduce


```
import numpy as np      
from sklearn.cluster import KMeans

X_train = np.random.random((10, 2))
kmeans = KMeans(n_clusters=3, random_state=0).fit(X_train)
```

### Expected Results

KMeans clusters

### Actual Results

`zsh: segmentation fault  python debugging.py`

This can't be a memory error, it's only a 10x2 matrix, any idea what's wrong?


### Versions

```shell
Python 3.10.4
Anaconda installation
>>> sklearn.__version__
'1.0.2'
>>> numpy.__version__
'1.22.3'
```

COMMENT:
Thank you for this comprehensive comment, @alinacherkas.

I agree with your analysis.

I think that:
 - Option 1 should work in most scenarios as a lot of packages are being uploaded on conda-forge, and are more up to date and cover a variety of combinations of OSes, architectures, and versions of Python than on the defaults' channels and do not come with relicensing.
 - Option 2 is more flexible and would fit all the use-cases. I would add that [channels ordering and channel priority](https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-channels.html) allows having control over packages' resolution (e.g. conda-forge can be set as having precedence over other channels which can be used as fall-backs).

Generally, I think we agree on using conda packages over wheels for the reasons given in [pypackaging-native](https://pypackaging-native.github.io/).

Out of curiosity, are you using other conda channels than `defaults` or `conda-forge`?

Labels: Bug, Documentation, help wanted, module:cluster, OS:macOS
Segmentation Fault in KMeans on OSX

### Describe the bug

Hi when I run this code

```
import numpy as np      
from sklearn.cluster import KMeans

X_train = np.random.RandomState(0).random((10, 2))
kmeans = KMeans(n_clusters=3, random_state=0).fit(X_train)
```

EDIT by @ogrisel: inserted `.RandomState(0)` in the above snippet to make the reproducer deterministic.

I get this error

`zsh: segmentation fault  python debugging.py`

This can't be a memory error, it's only a 10x2 matrix, any idea what's wrong?

Python 3.10.4
Anaconda installation
>>> sklearn.__version__
'1.0.2'
>>> numpy.__version__
'1.22.3'


### Steps/Code to Reproduce


```
import numpy as np      
from sklearn.cluster import KMeans

X_train = np.random.random((10, 2))
kmeans = KMeans(n_clusters=3, random_state=0).fit(X_train)
```

### Expected Results

KMeans clusters

### Actual Results

`zsh: segmentation fault  python debugging.py`

This can't be a memory error, it's only a 10x2 matrix, any idea what's wrong?


### Versions

```shell
Python 3.10.4
Anaconda installation
>>> sklearn.__version__
'1.0.2'
>>> numpy.__version__
'1.22.3'
```

COMMENT:
> You could add something like this:
> 
> _When using conda on MacOS (only MacOS and only on Intel Macs?), NumPy and SciPy must be installed from the same channel as scikit-learn (`conda-forge`) to avoid compatibility issues between Intel OpenMP and LLVM OpenMP._

I think adding a short sentence to the install docs would be good. I'd make it something like the advice from https://github.com/scikit-learn/scikit-learn/issues/23574#issuecomment-1782261722 - "make sure to install numpy, scipy and scikit-learn from the same conda channel".

Labels: Bug, Documentation, help wanted, module:cluster, OS:macOS
Segmentation Fault in KMeans on OSX

### Describe the bug

Hi when I run this code

```
import numpy as np      
from sklearn.cluster import KMeans

X_train = np.random.RandomState(0).random((10, 2))
kmeans = KMeans(n_clusters=3, random_state=0).fit(X_train)
```

EDIT by @ogrisel: inserted `.RandomState(0)` in the above snippet to make the reproducer deterministic.

I get this error

`zsh: segmentation fault  python debugging.py`

This can't be a memory error, it's only a 10x2 matrix, any idea what's wrong?

Python 3.10.4
Anaconda installation
>>> sklearn.__version__
'1.0.2'
>>> numpy.__version__
'1.22.3'


### Steps/Code to Reproduce


```
import numpy as np      
from sklearn.cluster import KMeans

X_train = np.random.random((10, 2))
kmeans = KMeans(n_clusters=3, random_state=0).fit(X_train)
```

### Expected Results

KMeans clusters

### Actual Results

`zsh: segmentation fault  python debugging.py`

This can't be a memory error, it's only a 10x2 matrix, any idea what's wrong?


### Versions

```shell
Python 3.10.4
Anaconda installation
>>> sklearn.__version__
'1.0.2'
>>> numpy.__version__
'1.22.3'
```

COMMENT:
@jjerphan , yes, occasionally I use other conda channels for packages that instruct so.  For example, `plotly::plotly`, `plotly::python-kaleido` and `pytorch::pytorch`.

Labels: Bug, Documentation, help wanted, module:cluster, OS:macOS
Yeo-Johnson Transformer

### Describe the bug

Yeo-Johnson Transformer converges to a transformer that produces a 0 array. I think this happens because the MLE of the Yeo-Johnson converges to a lambda which produces 0 variance transformations. The log-likelihood function is inf for this value of lambda, hence this lambda is selected.

### Steps/Code to Reproduce

```
import numpy as np
from sklearn.preprocessing import PowerTransformer

test_arr = np.array(
    [
        330117.5,
        651193.35,
        364335.63,
        2136036.01,
        1184539.05,
        1186871.87,
        2310647.36,
        860183.78,
        237451.79,
        2324365.47,
        1942665.42,
        1441017.74,
        1214875.44,
        530633.22,
        2528684.53,
        371882.3,
        400359.28,
        798128.31,
        2458850.02,
        35565.16,
        655361.06,
        979121.35,
        2455851.58,
        656799.58,
        551429.2,
        122855.01,
        714573.03,
        1065608.98,
        656657.61,
        327573.11,
        697887.49,
        3853463.06,
        60303.21,
        778135.06,
        509140.84,
        617577.08,
        2112523.9,
        164003.18,
        484017.51,
        1250302.48,
        2342622.41,
        349077.45,
        1069976.02,
        1005329.1,
        836722.74,
        1126835.94,
        6773842.44,
        554150.9,
        18207498.84,
        2413814.68,
        3056937.64,
        1493907.08,
        420165.71,
        424720.48,
        506684.87,
        3138440.77,
        4737292.56,
        6619302.87,
        178811.87,
        1931526.68,
        155927053.78,
        735076.02,
        20403952.84,
        2712149.03,
        329014.58,
        894241.92,
        966598.77,
        1105177.67,
        1122957.48,
        3435244.08,
        3485325.79,
        1424915.64,
        684150.05,
        977746.26,
        37386.1,
        1616938.1,
        1517666.31,
        753096.39,
    ]
)

transformer = PowerTransformer("yeo-johnson")
transformed = transformer.fit_transform(test_arr.reshape(-1, 1))
print(transformed)
```

### Expected Results

A non-zero np.ndarray

### Actual Results

A zero np.ndarray

### Versions

```shell
System:
    python: 3.8.6 (default, May 23 2022, 16:30:31)  [GCC 11.3.0]
executable: /Users/pablobarbero/projects/machine-learning-platform/etp_rl_postprocessing/.venv/bin/python
   machine: macOS-12.4-x86_64-i386-64bit

Python dependencies:
       pip: 22.0.3
setuptools: 60.6.0
   sklearn: 0.22.2.post1
     numpy: 1.22.4
     scipy: 1.5.4
    Cython: 0.29.30
    pandas: 1.2.5
matplotlib: 3.5.2
    joblib: 1.1.0

Built with OpenMP: True
```

COMMENT:
Is it a weird distribution such as in https://github.com/scikit-learn/scikit-learn/issues/23319 where Yeo-Johnson would not be adapted?

Labels: Bug, Needs Triage
Yeo-Johnson Transformer

### Describe the bug

Yeo-Johnson Transformer converges to a transformer that produces a 0 array. I think this happens because the MLE of the Yeo-Johnson converges to a lambda which produces 0 variance transformations. The log-likelihood function is inf for this value of lambda, hence this lambda is selected.

### Steps/Code to Reproduce

```
import numpy as np
from sklearn.preprocessing import PowerTransformer

test_arr = np.array(
    [
        330117.5,
        651193.35,
        364335.63,
        2136036.01,
        1184539.05,
        1186871.87,
        2310647.36,
        860183.78,
        237451.79,
        2324365.47,
        1942665.42,
        1441017.74,
        1214875.44,
        530633.22,
        2528684.53,
        371882.3,
        400359.28,
        798128.31,
        2458850.02,
        35565.16,
        655361.06,
        979121.35,
        2455851.58,
        656799.58,
        551429.2,
        122855.01,
        714573.03,
        1065608.98,
        656657.61,
        327573.11,
        697887.49,
        3853463.06,
        60303.21,
        778135.06,
        509140.84,
        617577.08,
        2112523.9,
        164003.18,
        484017.51,
        1250302.48,
        2342622.41,
        349077.45,
        1069976.02,
        1005329.1,
        836722.74,
        1126835.94,
        6773842.44,
        554150.9,
        18207498.84,
        2413814.68,
        3056937.64,
        1493907.08,
        420165.71,
        424720.48,
        506684.87,
        3138440.77,
        4737292.56,
        6619302.87,
        178811.87,
        1931526.68,
        155927053.78,
        735076.02,
        20403952.84,
        2712149.03,
        329014.58,
        894241.92,
        966598.77,
        1105177.67,
        1122957.48,
        3435244.08,
        3485325.79,
        1424915.64,
        684150.05,
        977746.26,
        37386.1,
        1616938.1,
        1517666.31,
        753096.39,
    ]
)

transformer = PowerTransformer("yeo-johnson")
transformed = transformer.fit_transform(test_arr.reshape(-1, 1))
print(transformed)
```

### Expected Results

A non-zero np.ndarray

### Actual Results

A zero np.ndarray

### Versions

```shell
System:
    python: 3.8.6 (default, May 23 2022, 16:30:31)  [GCC 11.3.0]
executable: /Users/pablobarbero/projects/machine-learning-platform/etp_rl_postprocessing/.venv/bin/python
   machine: macOS-12.4-x86_64-i386-64bit

Python dependencies:
       pip: 22.0.3
setuptools: 60.6.0
   sklearn: 0.22.2.post1
     numpy: 1.22.4
     scipy: 1.5.4
    Cython: 0.29.30
    pandas: 1.2.5
matplotlib: 3.5.2
    joblib: 1.1.0

Built with OpenMP: True
```

COMMENT:
The original issue was using scikit-learn v0.22. I tested this on 1.1 and `main` and a non-zero array was returned.

Upgrading to v1.1 should resolve your issue.

Labels: Bug, Needs Triage
Allow subclasses to pass through check_array()

### Describe the workflow you want to enable

I have a subclass of `numpy.ndarray` which keeps track of axis labels: which axes represent time, spatial directions, independent samples, and response variables.  I have a `transform()` step in my pipeline that runs
`x = check_array(x, accept_sparse=("csr", "csc"), ...)`.
It's nice that this allows me to handle both numpy arrays and sparse inputs .  However, this [line](https://github.com/scikit-learn/scikit-learn/blob/b73ec3c3b39f2fcda37f943f47cf90b8f46253c4/sklearn/utils/validation.py#L847) of `scipy.utils.validation.check_array` downcasts anything that isn't a sparse array to a numpy array.  This is because `numpy.asarray` does not allow interception via `__array_ufunc__` or `__array_function__`, so subclasses cannot dictate how to handle its behavior.

### Describe your proposed solution

`isinstance` check to see if `array` is already a numpy array.  Not sure exactly how to enforce `order` and `dtype`, however.

### Describe alternatives you've considered, if relevant

User code instead repeats validation code from check_array.  In my case, that means importing the private function `_ensure_sparse_format()` and skipping or copypasting the other validation checks.

### Additional context

_No response_

COMMENT:
> isinstance check to see if array is already a numpy array. Not sure exactly how to enforce order and dtype, however.

I assume that the way forward is the Array API: https://github.com/scikit-learn/scikit-learn/issues/22352

Labels: New Feature, module:utils
Allow subclasses to pass through check_array()

### Describe the workflow you want to enable

I have a subclass of `numpy.ndarray` which keeps track of axis labels: which axes represent time, spatial directions, independent samples, and response variables.  I have a `transform()` step in my pipeline that runs
`x = check_array(x, accept_sparse=("csr", "csc"), ...)`.
It's nice that this allows me to handle both numpy arrays and sparse inputs .  However, this [line](https://github.com/scikit-learn/scikit-learn/blob/b73ec3c3b39f2fcda37f943f47cf90b8f46253c4/sklearn/utils/validation.py#L847) of `scipy.utils.validation.check_array` downcasts anything that isn't a sparse array to a numpy array.  This is because `numpy.asarray` does not allow interception via `__array_ufunc__` or `__array_function__`, so subclasses cannot dictate how to handle its behavior.

### Describe your proposed solution

`isinstance` check to see if `array` is already a numpy array.  Not sure exactly how to enforce `order` and `dtype`, however.

### Describe alternatives you've considered, if relevant

User code instead repeats validation code from check_array.  In my case, that means importing the private function `_ensure_sparse_format()` and skipping or copypasting the other validation checks.

### Additional context

_No response_

COMMENT:
I think this issue is mostly orthogonal to the Array API issue.

The most straight forward thing to do is the replace the `asarray` call with [np.asanyarray](https://numpy.org/doc/stable/reference/generated/numpy.asanyarray.html), which preserves the subclass. Note this is technically a change in behavior for `check_array`, but I do not see any immediately issues with returning a ndarray subclass.

Labels: New Feature, module:utils
Include print counter for HalvingGridSearch in verbose=3 mode

### Describe the workflow you want to enable

Dear all,
when using HalvingGridSearch it is very likely, that (especially the first iteration) it contains 100's to 1000's of grid points. While monitoring in the verbose mode can be nice to get an idea about parameter importance, the only way to get an idea about the progress is to 'count rows'. 

### Describe your proposed solution

To get a better idea on the progress it would be nice to add the counter in the verbose = 3 output:
e.g. instead of 
"[CV 1/3] END C=5, class_weight=None, degree=2, gamma=1, kernel=rbf;, score=(train=-0.050, test=-0.201) total time=  13.5s"

"[**Iter 0; Fit Number 1234 of 4321;** CV 1/3] END C=5, class_weight=None, degree=2, gamma=1, kernel=rbf;, score=(train=-0.050, test=-0.201) total time=  13.5s"

Both, Iter and total number of fits in the current iteration are provided at the beginning of each iteration and thus would require only minor changes.


### Describe alternatives you've considered, if relevant

_No response_

### Additional context

_No response_

COMMENT:
Thank you for opening this issue. Moving forward, the work in https://github.com/scikit-learn/scikit-learn/pull/22000 will more elegantly resolve this issue.

Labels: New Feature, module:model_selection
passing cross validation data to custom score function in GridSearchCV

### Describe the workflow you want to enable

Custom score function some time need the feature values also but there is no way we could do this .We can not the use same dataset which we have used for gridsearchcv ,reason is the data we sent will be splited into training and testing data and passed to score function separately. 

### Describe your proposed solution

Just while passing y_true and y_pred , pass validation dataset also .

### Describe alternatives you've considered, if relevant

_No response_

### Additional context

_No response_

COMMENT:
Can you describe with some code (or pseudo-code) your use case. It would help to see which data are required at which stage of the search cv. The proposal of the sample-props might solve this but I am not sure.

Labels: New Feature, module:model_selection, Needs Reproducible Code, Metadata Routing
passing cross validation data to custom score function in GridSearchCV

### Describe the workflow you want to enable

Custom score function some time need the feature values also but there is no way we could do this .We can not the use same dataset which we have used for gridsearchcv ,reason is the data we sent will be splited into training and testing data and passed to score function separately. 

### Describe your proposed solution

Just while passing y_true and y_pred , pass validation dataset also .

### Describe alternatives you've considered, if relevant

_No response_

### Additional context

_No response_

COMMENT:
@Sanath91009 you can create custom metrics which takes not only y_true, y_pred but X (data) as well and withing that custom metric do use of any feature from X as you wish. If you mean this. Would be nice if you make the proposal more explicit. Thanks.

Labels: New Feature, module:model_selection, Needs Reproducible Code, Metadata Routing