Talip7/scikit-learn-issues-multilabel huggingface dataset:
LedoitWolf.fit() crashes Jupyter Notebook

### Describe the bug

Hi, when i used LedoitWolf.fit(), my Jupyter Notebook crashes immediately. I am using the toy example given in the source code of 
LedoitWolf class


### Steps/Code to Reproduce

```python
import numpy as np
from sklearn.covariance import LedoitWolf
real_cov = np.array([[.4, .2],[.2, .8]])
np.random.seed(0)
X = np.random.multivariate_normal(mean=[0, 0],cov=real_cov,size=50)
cov = LedoitWolf().fit(X)
```

### Expected Results

It is exptected to fit the estimator.

### Actual Results

However kernel crashes. sklearn.show_versions() also produce a WinError.

### Versions

```shell
Sklearn version is 1.3.2
```

COMMENT:
On the `show_versions`, it looks like something goes wrong with MKL and `threadpoolctl`. I could not find anything in the issue tracker. @jeremiedbb did you ever notice something similar?

The other error look like a segmentation fault. The weird thing is that we only have Python code so we should not have any memory issue on the scikit-learn side.

Can you list the version of scipy and numpy that you have installed (since `show_versions()` does not work).

Labels: Bug, Needs Info
LedoitWolf.fit() crashes Jupyter Notebook

### Describe the bug

Hi, when i used LedoitWolf.fit(), my Jupyter Notebook crashes immediately. I am using the toy example given in the source code of 
LedoitWolf class


### Steps/Code to Reproduce

```python
import numpy as np
from sklearn.covariance import LedoitWolf
real_cov = np.array([[.4, .2],[.2, .8]])
np.random.seed(0)
X = np.random.multivariate_normal(mean=[0, 0],cov=real_cov,size=50)
cov = LedoitWolf().fit(X)
```

### Expected Results

It is exptected to fit the estimator.

### Actual Results

However kernel crashes. sklearn.show_versions() also produce a WinError.

### Versions

```shell
Sklearn version is 1.3.2
```

COMMENT:
Could you create a new environment and install the package from the `conda-forge` channel:

```
conda create --name myenv scikit-learn -c conda-forge
```

You can add other packages. The only thing is to make sure to have `-c conda-forge`. I want to understand if the problem come from the `anaconda` packaging.

With the `conda-forge` channel you will get `openblas` instead of `mkl`.

Labels: Bug, Needs Info
LedoitWolf.fit() crashes Jupyter Notebook

### Describe the bug

Hi, when i used LedoitWolf.fit(), my Jupyter Notebook crashes immediately. I am using the toy example given in the source code of 
LedoitWolf class


### Steps/Code to Reproduce

```python
import numpy as np
from sklearn.covariance import LedoitWolf
real_cov = np.array([[.4, .2],[.2, .8]])
np.random.seed(0)
X = np.random.multivariate_normal(mean=[0, 0],cov=real_cov,size=50)
cov = LedoitWolf().fit(X)
```

### Expected Results

It is exptected to fit the estimator.

### Actual Results

However kernel crashes. sklearn.show_versions() also produce a WinError.

### Versions

```shell
Sklearn version is 1.3.2
```

COMMENT:
I followed your suggestion and `LedoitWolf().fit(X)` worked as expected in virtual environment. However when i uninstall scikit-learn and re-install it with conda it still crashes on my main environment.

Labels: Bug, Needs Info
LedoitWolf.fit() crashes Jupyter Notebook

### Describe the bug

Hi, when i used LedoitWolf.fit(), my Jupyter Notebook crashes immediately. I am using the toy example given in the source code of 
LedoitWolf class


### Steps/Code to Reproduce

```python
import numpy as np
from sklearn.covariance import LedoitWolf
real_cov = np.array([[.4, .2],[.2, .8]])
np.random.seed(0)
X = np.random.multivariate_normal(mean=[0, 0],cov=real_cov,size=50)
cov = LedoitWolf().fit(X)
```

### Expected Results

It is exptected to fit the estimator.

### Actual Results

However kernel crashes. sklearn.show_versions() also produce a WinError.

### Versions

```shell
Sklearn version is 1.3.2
```

COMMENT:
Yes it will but it tell us that this something to do with the conda-maintained package and we are not in charge of it. I would bet that there is something fishy with MKL. 

I'll like to reproduce the issue but I don't have a windows 10 machine. I'll try to find a way.

Labels: Bug, Needs Info
LedoitWolf.fit() crashes Jupyter Notebook

### Describe the bug

Hi, when i used LedoitWolf.fit(), my Jupyter Notebook crashes immediately. I am using the toy example given in the source code of 
LedoitWolf class


### Steps/Code to Reproduce

```python
import numpy as np
from sklearn.covariance import LedoitWolf
real_cov = np.array([[.4, .2],[.2, .8]])
np.random.seed(0)
X = np.random.multivariate_normal(mean=[0, 0],cov=real_cov,size=50)
cov = LedoitWolf().fit(X)
```

### Expected Results

It is exptected to fit the estimator.

### Actual Results

However kernel crashes. sklearn.show_versions() also produce a WinError.

### Versions

```shell
Sklearn version is 1.3.2
```

COMMENT:
I came here because I have the same issue, but in `NearestNeighbors.kneighbors()`
Also a Ryzen CPU
```

System:
    python: 3.12.1 | packaged by conda-forge | (main, Dec 23 2023, 07:53:56) [MSC v.1937 64 bit (AMD64)]
executable: [d:\programme\miniconda\envs\py310\python.exe](file:///D:/programme/miniconda/envs/py310/python.exe)
   machine: Windows-10-10.0.19045-SP0

Python dependencies:
      sklearn: 1.4.1.post1
          pip: 24.0
   setuptools: 69.1.1
        numpy: 1.26.4
        scipy: 1.12.0
       Cython: None
       pandas: 2.2.1
   matplotlib: 3.8.3
       joblib: 1.3.2
threadpoolctl: 3.3.0

Built with OpenMP: True
```

Edit: It seems switching the VSCode Jupyter Extension from Beta to Stable solves this lmao

Labels: Bug, Needs Info
LedoitWolf.fit() crashes Jupyter Notebook

### Describe the bug

Hi, when i used LedoitWolf.fit(), my Jupyter Notebook crashes immediately. I am using the toy example given in the source code of 
LedoitWolf class


### Steps/Code to Reproduce

```python
import numpy as np
from sklearn.covariance import LedoitWolf
real_cov = np.array([[.4, .2],[.2, .8]])
np.random.seed(0)
X = np.random.multivariate_normal(mean=[0, 0],cov=real_cov,size=50)
cov = LedoitWolf().fit(X)
```

### Expected Results

It is exptected to fit the estimator.

### Actual Results

However kernel crashes. sklearn.show_versions() also produce a WinError.

### Versions

```shell
Sklearn version is 1.3.2
```

COMMENT:
This seems like an issue with packaging rather than scikit-learn, so I am going to close this one.

If you disagree, it would be great if you could provide the command to create a conda environment or virtualenv from scratch so that someone can try to reproduce.

About the weird error with `sklearn.show_versions()`, this seems related to an issue with the mkl wheel (exact same cryptic WindowsError):
https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Intel-MKL-distribution-for-Python-is-broken-as-of-version-2024/m-p/1555753

I managed at one point to reproduce the same symptoms in a Windows VM but I don't manage to do it anymore in a new environment. I have no idea why there is a mkl wheel but I suspect that the issue is mixing conda and pip for the same packages.

@SandroMartens your issue seems different and likely an environment thing rather than a problem in scikit-learn. If your issue persists, please open a separate issue with the code needed to reproduce it and the command to create a conda environment (or virtualenv) from scratch.

Labels: Bug, Needs Info
Expanded ColumnTransformer functionality -- transforming subsets of data

### Describe the workflow you want to enable (edited)

the ability to (inverse_)transform data corresponding to a subset of the ColumnTransformer's component transformations

### Describe your proposed solution

Data of a smaller size can be passed in with a new keyword that identifies the relevant component transformations by name

### Describe alternatives you've considered, if relevant

a function that subsets a ColumnTransformer object, including adjusting the column numbers

### Additional context

In artificial intelligence applications, the researcher may want to transform an entire dataset with column groups for learning, but then transform new data corresponding just to interventions or predictions using the same transformations at a later time. Hence, the need to be able to subset a ColumnTransform or pass in only a part of the data.

See #27957 for more discussion.

COMMENT:
We have a PR candidate here: https://github.com/scikit-learn/scikit-learn/pull/11639

@thomasjpfan This is maybe a user-case that you were searching for.
The `inverse_transform` is also useful in this context: https://github.com/scikit-learn/scikit-learn/pull/22574

Labels: New Feature
Expanded ColumnTransformer functionality -- transforming subsets of data

### Describe the workflow you want to enable (edited)

the ability to (inverse_)transform data corresponding to a subset of the ColumnTransformer's component transformations

### Describe your proposed solution

Data of a smaller size can be passed in with a new keyword that identifies the relevant component transformations by name

### Describe alternatives you've considered, if relevant

a function that subsets a ColumnTransformer object, including adjusting the column numbers

### Additional context

In artificial intelligence applications, the researcher may want to transform an entire dataset with column groups for learning, but then transform new data corresponding just to interventions or predictions using the same transformations at a later time. Hence, the need to be able to subset a ColumnTransform or pass in only a part of the data.

See #27957 for more discussion.

COMMENT:
This issue is thus a duplicate from https://github.com/scikit-learn/scikit-learn/issues/11463

Labels: New Feature
Expanded ColumnTransformer functionality -- transforming subsets of data

### Describe the workflow you want to enable (edited)

the ability to (inverse_)transform data corresponding to a subset of the ColumnTransformer's component transformations

### Describe your proposed solution

Data of a smaller size can be passed in with a new keyword that identifies the relevant component transformations by name

### Describe alternatives you've considered, if relevant

a function that subsets a ColumnTransformer object, including adjusting the column numbers

### Additional context

In artificial intelligence applications, the researcher may want to transform an entire dataset with column groups for learning, but then transform new data corresponding just to interventions or predictions using the same transformations at a later time. Hence, the need to be able to subset a ColumnTransform or pass in only a part of the data.

See #27957 for more discussion.

COMMENT:
@glemaitre Sorry I didn't notice that other issue. However this is not a duplicate because I am requesting one additional feature -- the ability to pass in a subset of the data

Labels: New Feature
Expanded ColumnTransformer functionality -- transforming subsets of data

### Describe the workflow you want to enable (edited)

the ability to (inverse_)transform data corresponding to a subset of the ColumnTransformer's component transformations

### Describe your proposed solution

Data of a smaller size can be passed in with a new keyword that identifies the relevant component transformations by name

### Describe alternatives you've considered, if relevant

a function that subsets a ColumnTransformer object, including adjusting the column numbers

### Additional context

In artificial intelligence applications, the researcher may want to transform an entire dataset with column groups for learning, but then transform new data corresponding just to interventions or predictions using the same transformations at a later time. Hence, the need to be able to subset a ColumnTransform or pass in only a part of the data.

See #27957 for more discussion.

COMMENT:
I have now edited the issue above to focus just on the unique part of this request. Perhaps the Triage label could be re-added?

Labels: New Feature
Expanded ColumnTransformer functionality -- transforming subsets of data

### Describe the workflow you want to enable (edited)

the ability to (inverse_)transform data corresponding to a subset of the ColumnTransformer's component transformations

### Describe your proposed solution

Data of a smaller size can be passed in with a new keyword that identifies the relevant component transformations by name

### Describe alternatives you've considered, if relevant

a function that subsets a ColumnTransformer object, including adjusting the column numbers

### Additional context

In artificial intelligence applications, the researcher may want to transform an entire dataset with column groups for learning, but then transform new data corresponding just to interventions or predictions using the same transformations at a later time. Hence, the need to be able to subset a ColumnTransform or pass in only a part of the data.

See #27957 for more discussion.

COMMENT:
Hi @rebeccaherman1 : what do you mean by "subset of the data"? How is it defined?

Labels: New Feature
Expanded ColumnTransformer functionality -- transforming subsets of data

### Describe the workflow you want to enable (edited)

the ability to (inverse_)transform data corresponding to a subset of the ColumnTransformer's component transformations

### Describe your proposed solution

Data of a smaller size can be passed in with a new keyword that identifies the relevant component transformations by name

### Describe alternatives you've considered, if relevant

a function that subsets a ColumnTransformer object, including adjusting the column numbers

### Additional context

In artificial intelligence applications, the researcher may want to transform an entire dataset with column groups for learning, but then transform new data corresponding just to interventions or predictions using the same transformations at a later time. Hence, the need to be able to subset a ColumnTransform or pass in only a part of the data.

See #27957 for more discussion.

COMMENT:
@GaelVaroquaux I mean columns associated with one or more of the transforms within the ColumnTransformer

For example, let's say my data is Mx10, and I define the ColumnTransformer using 
```python
transformers = [('X', StandardScaler(total_variance=True), [0,1,2]),
                ('Y', StandardScaler(total_variance=True), [3,4,5,6,7]),
                ('Z', StandardScaler(total_variance=True), [8,9])]
```
Then, maybe later, I'd like to pass in data corresponding to just 'X' (original columns [0,1,2]) and 'Z' (original columns [8,9]), without 'Y'. I would then hope to pass in an M'x5 matrix, and identify the original columns the new data columns correspond to ([0,1,2,8,9]), or the transforms they correspond to (['X', 'Z')].

Labels: New Feature
Expanded ColumnTransformer functionality -- transforming subsets of data

### Describe the workflow you want to enable (edited)

the ability to (inverse_)transform data corresponding to a subset of the ColumnTransformer's component transformations

### Describe your proposed solution

Data of a smaller size can be passed in with a new keyword that identifies the relevant component transformations by name

### Describe alternatives you've considered, if relevant

a function that subsets a ColumnTransformer object, including adjusting the column numbers

### Additional context

In artificial intelligence applications, the researcher may want to transform an entire dataset with column groups for learning, but then transform new data corresponding just to interventions or predictions using the same transformations at a later time. Hence, the need to be able to subset a ColumnTransform or pass in only a part of the data.

See #27957 for more discussion.

COMMENT:
If we want to support this feature, I'll go with "slicing a column transformer":

```python
transformers = [('X', StandardScaler(total_variance=True), [0,1,2]),
                ('Y', StandardScaler(total_variance=True), [3,4,5,6,7]),
                ('Z', StandardScaler(total_variance=True), [8,9])]
ct = ColumnTransform(transformers)
ct.fit(X)
ct_sliced = ct[["X", "Z"]]

ct_sliced.transform(X_subset)
```

We already have some precedence for this with `Pipeline` slicing.

Labels: New Feature
Expanded ColumnTransformer functionality -- transforming subsets of data

### Describe the workflow you want to enable (edited)

the ability to (inverse_)transform data corresponding to a subset of the ColumnTransformer's component transformations

### Describe your proposed solution

Data of a smaller size can be passed in with a new keyword that identifies the relevant component transformations by name

### Describe alternatives you've considered, if relevant

a function that subsets a ColumnTransformer object, including adjusting the column numbers

### Additional context

In artificial intelligence applications, the researcher may want to transform an entire dataset with column groups for learning, but then transform new data corresponding just to interventions or predictions using the same transformations at a later time. Hence, the need to be able to subset a ColumnTransform or pass in only a part of the data.

See #27957 for more discussion.

COMMENT:
@thomasjpfan This would be wonderful. 

I tried to look through the code for `ColumnTransformer`, but it is a little too complicated for me to really understand everything that's going on in order to modify it in a reasonable amount of time.

Would someone else who is more familiar with the code be willing to implement this? Or discuss in more detail how it would be best implemented?

Labels: New Feature
Adding (Mini-Batch) Spherical K-Means Clustering

### Describe the workflow you want to enable

We need to use the spherical k-means algorithm to cluster text embeddings on a hypersphere. Currently there seem to be no reliable implementations available. Since we have a lot of input-data, we would like to implement the mini-batch version of the algorithm.

### Describe your proposed solution

Spherical k-means is a trivial modifications of normal k-means clustering where the centroids are projected onto the hypersphere in each step. Thus, we could add a boolean option `spherical=False` to the constructor of `MiniBatchKMeans` that toggles between standard k-means and spherical k-means. It is my understanding that we would then only have to l2-normalize the input data, l2-normalize the initial centroids here: https://github.com/scikit-learn/scikit-learn/blob/91d273ae892851ec3bdc4a21cffe163fbaed40f0/sklearn/cluster/_kmeans.py#L2128 and l2-normalize the updated centroids after this call: https://github.com/scikit-learn/scikit-learn/blob/91d273ae892851ec3bdc4a21cffe163fbaed40f0/sklearn/cluster/_kmeans.py#L2174 

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

There is the [spherecluster](https://github.com/jasonlaska/spherecluster) module, which has been broken since the release of scikit-learn 1.0.0 and is no longer maintained, therefore no viable alternative for users.

### Additional context

We are happy to prepare a PR for this ourselves!

COMMENT:
Out of curiosity, do you witness a huge difference between the usual k-means and the spherical k-means on the final supervised task (and not the clustering task)?

Labels: New Feature
Adding (Mini-Batch) Spherical K-Means Clustering

### Describe the workflow you want to enable

We need to use the spherical k-means algorithm to cluster text embeddings on a hypersphere. Currently there seem to be no reliable implementations available. Since we have a lot of input-data, we would like to implement the mini-batch version of the algorithm.

### Describe your proposed solution

Spherical k-means is a trivial modifications of normal k-means clustering where the centroids are projected onto the hypersphere in each step. Thus, we could add a boolean option `spherical=False` to the constructor of `MiniBatchKMeans` that toggles between standard k-means and spherical k-means. It is my understanding that we would then only have to l2-normalize the input data, l2-normalize the initial centroids here: https://github.com/scikit-learn/scikit-learn/blob/91d273ae892851ec3bdc4a21cffe163fbaed40f0/sklearn/cluster/_kmeans.py#L2128 and l2-normalize the updated centroids after this call: https://github.com/scikit-learn/scikit-learn/blob/91d273ae892851ec3bdc4a21cffe163fbaed40f0/sklearn/cluster/_kmeans.py#L2174 

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

There is the [spherecluster](https://github.com/jasonlaska/spherecluster) module, which has been broken since the release of scikit-learn 1.0.0 and is no longer maintained, therefore no viable alternative for users.

### Additional context

We are happy to prepare a PR for this ourselves!

COMMENT:
I'm not completely sure what you mean by supervised task, as we don't have anything downstream of the clustering. We simply use the clustering algorithm as part of the [massive text embedding benchmark](http://github.com/embeddings-benchmark/mteb) and compute the v-measure to ground-truth labels. Our idea was that using spherical k-means may improve this metric, but preliminary tests seem to indicate that that's not the case.

Labels: New Feature
Adding (Mini-Batch) Spherical K-Means Clustering

### Describe the workflow you want to enable

We need to use the spherical k-means algorithm to cluster text embeddings on a hypersphere. Currently there seem to be no reliable implementations available. Since we have a lot of input-data, we would like to implement the mini-batch version of the algorithm.

### Describe your proposed solution

Spherical k-means is a trivial modifications of normal k-means clustering where the centroids are projected onto the hypersphere in each step. Thus, we could add a boolean option `spherical=False` to the constructor of `MiniBatchKMeans` that toggles between standard k-means and spherical k-means. It is my understanding that we would then only have to l2-normalize the input data, l2-normalize the initial centroids here: https://github.com/scikit-learn/scikit-learn/blob/91d273ae892851ec3bdc4a21cffe163fbaed40f0/sklearn/cluster/_kmeans.py#L2128 and l2-normalize the updated centroids after this call: https://github.com/scikit-learn/scikit-learn/blob/91d273ae892851ec3bdc4a21cffe163fbaed40f0/sklearn/cluster/_kmeans.py#L2174 

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

There is the [spherecluster](https://github.com/jasonlaska/spherecluster) module, which has been broken since the release of scikit-learn 1.0.0 and is no longer maintained, therefore no viable alternative for users.

### Additional context

We are happy to prepare a PR for this ourselves!

COMMENT:
I was interested in such evaluation. Since clustering is unsupervised, it is not a given to have ground-truth and using an underlying supervised class where the found cluster are used could be used as a proxy.

> Our idea was that using spherical k-means may improve this metric, but preliminary tests seem to indicate that that's not the case.

This is what would help us to not if we should include the feature or not. In addition to the scientific literature, we want to include feature that have a practical impact (better performance, faster training/inference, etc.).

So if the method does not bring that much compared to what we can do with the current tools (k-means/k-means with dimension reduction), I think that it tells us that we should not include it. But your benchmark will bring the facts towards this decision.

Labels: New Feature