Talip7/scikit-learn-issues-multilabel huggingface dataset:
euclidean_distances with float64 x,y and float32 xx and yy

### Describe the bug

When running `euclidean_distances` I think it is possible to get to [this](https://github.com/scikit-learn/scikit-learn/blob/d99b728b3a7952b2111cf5e0cb5d14f92c6f3a80/sklearn/metrics/pairwise.py#L380) line of code with `XX` being `None`. This will happen when the input `X` and `Y` are `float64` but `X_norm_squared` and `Y_norm_squared` are `float32`.

### Steps/Code to Reproduce

```python
import numpy as np
from sklearn.metrics.pairwise import euclidean_distances

x = np.random.randint(0, 10, size=(100, 5)).astype(np.float64)
y = np.random.randint(0, 10, size=(100, 5)).astype(np.float64)

xx = np.einsum("ij,ij->i", x, x)
yy = np.einsum("ij,ij->i", y, y)

euclidean_distances(x, y, Y_norm_squared=yy.astype(np.float32), X_norm_squared=xx.astype(np.float32))
```

### Expected Results

No error is thrown

### Actual Results

```
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ageorgiou/projects/test/venv/lib/python3.10/site-packages/sklearn/metrics/pairwise.py", line 338, in euclidean_distances
    return _euclidean_distances(X, Y, X_norm_squared, Y_norm_squared, squared)
  File "/home/ageorgiou/projects/test/venv/lib/python3.10/site-packages/sklearn/metrics/pairwise.py", line 380, in _euclidean_distances
    distances += XX
numpy.core._exceptions._UFuncOutputCastingError: Cannot cast ufunc 'add' output from dtype('O') to dtype('float64') with casting rule 'same_kind'
```

### Versions

```shell
System:
    python: 3.10.6 (main, Oct 30 2022, 13:35:37) [GCC 12.2.0]
executable: /home/ageorgiou/projects/test/venv/bin/python
   machine: Linux-6.2.12-1-MANJARO-x86_64-with-glibc2.38

Python dependencies:
      sklearn: 1.3.1
          pip: 22.2.1
   setuptools: 63.2.0
        numpy: 1.26.1
        scipy: 1.11.3
       Cython: None
       pandas: None
   matplotlib: None
       joblib: 1.3.2
threadpoolctl: 3.2.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
    num_threads: 8
         prefix: libopenblas
       filepath: /home/ageorgiou/projects/test/venv/lib/python3.10/site-packages/numpy.libs/libopenblas64_p-r0-0cf96a72.3.23.dev.so
        version: 0.3.23.dev
threading_layer: pthreads
   architecture: Haswell

       user_api: openmp
   internal_api: openmp
    num_threads: 8
         prefix: libgomp
       filepath: /home/ageorgiou/projects/test/venv/lib/python3.10/site-packages/scikit_learn.libs/libgomp-a34b3233.so.1.0.0
        version: None

       user_api: blas
   internal_api: openblas
    num_threads: 8
         prefix: libopenblas
       filepath: /home/ageorgiou/projects/test/venv/lib/python3.10/site-packages/scipy.libs/libopenblasp-r0-23e5df77.3.21.dev.so
        version: 0.3.21.dev
threading_layer: pthreads
   architecture: Haswell

```
```

COMMENT:
The previous code path is triggered (the Cython implementations are not used), I might have a look at it when I get some time.

Anyone should feel free to fix it if needed.

Labels: Bug
sklearn PCA rotates a single vector

### Describe the bug

The issue we recently discovered is that sklearn PCA rotates the input when only a single variable is fed into the model.  

I am aware there are infinite rotations when there is a single vector fed into the model, however, the output from PCA should intuitively make sense. So I suggest hard coding this scenario (which I guess already done in R)


### Steps/Code to Reproduce
```python
import numpy as np
from sklearn.decomposition import PCA

x = np.array([1,2,3,4,5,6,7,8,9,10.]).reshape(-1,1).astype('float64')

p = PCA().fit_transform(x)
p
```
### output:
```
array([[ 4.5],
       [ 3.5],
       [ 2.5],
       [ 1.5],
       [ 0.5],
       [-0.5],
       [-1.5],
       [-2.5],
       [-3.5],
       [-4.5]])
```

as we see here the value 4.5 is corresponding to the smallest value in the set (1) and the value -4.5 is corresponding to the highest value in the input set (10).

### Expected Results:
```
array([[-4.5],
       [-3.5],
       [-2.5],
       [-1.5],
       [-0.5],
       [ 0.5],
       [ 1.5],
       [ 2.5],
       [ 3.5],
       [ 4.5]])
```



### Steps/Code to Reproduce

```
from sklearn.decomposition import PCA

x= np.array([1,2,3,4,5,6,7,8,9,10.]).reshape(-1,1).astype('float64')

p = PCA().fit_transform(x)
p
```

### Expected Results

```
array([[-4.5],
       [-3.5],
       [-2.5],
       [-1.5],
       [-0.5],
       [ 0.5],
       [ 1.5],
       [ 2.5],
       [ 3.5],
       [ 4.5]])
```

### Actual Results

```
array([[ 4.5],
       [ 3.5],
       [ 2.5],
       [ 1.5],
       [ 0.5],
       [-0.5],
       [-1.5],
       [-2.5],
       [-3.5],
       [-4.5]])
```

### Versions

```shell
System:
    python: 3.11.4 | packaged by Anaconda, Inc. | (main, Jul  5 2023, 13:47:18) [MSC v.1916 64 bit (AMD64)]
executable: e:\Users\***\miniconda3\python.exe
   machine: Windows-10-10.0.22621-SP0

Python dependencies:
      sklearn: 1.3.0
          pip: 23.2.1
   setuptools: 68.0.0
        numpy: 1.24.3
        scipy: 1.11.1
       Cython: None
       pandas: 2.0.3
   matplotlib: 3.7.1
       joblib: 1.2.0
threadpoolctl: 2.2.0

Built with OpenMP: True

threadpoolctl info:
       filepath: E:\Users\***\miniconda3\Library\bin\mkl_rt.2.dll
         prefix: mkl_rt
       user_api: blas
   internal_api: mkl
        version: 2023.1-Product
    num_threads: 8
threading_layer: intel

       filepath: E:\Users\***\miniconda3\vcomp140.dll
         prefix: vcomp
       user_api: openmp
   internal_api: openmp
        version: None
    num_threads: 16

       filepath: E:\Users\***\miniconda3\Library\bin\libiomp5md.dll
         prefix: libiomp
       user_api: openmp
   internal_api: openmp
        version: None
    num_threads: 16
```

COMMENT:
Thanks for trying. I should have been more explicit, what I meant is "can you try to nightly build of scikit-learn to see if the problem has been solved since the last release?"

Labels: Bug
sklearn PCA rotates a single vector

### Describe the bug

The issue we recently discovered is that sklearn PCA rotates the input when only a single variable is fed into the model.  

I am aware there are infinite rotations when there is a single vector fed into the model, however, the output from PCA should intuitively make sense. So I suggest hard coding this scenario (which I guess already done in R)


### Steps/Code to Reproduce
```python
import numpy as np
from sklearn.decomposition import PCA

x = np.array([1,2,3,4,5,6,7,8,9,10.]).reshape(-1,1).astype('float64')

p = PCA().fit_transform(x)
p
```
### output:
```
array([[ 4.5],
       [ 3.5],
       [ 2.5],
       [ 1.5],
       [ 0.5],
       [-0.5],
       [-1.5],
       [-2.5],
       [-3.5],
       [-4.5]])
```

as we see here the value 4.5 is corresponding to the smallest value in the set (1) and the value -4.5 is corresponding to the highest value in the input set (10).

### Expected Results:
```
array([[-4.5],
       [-3.5],
       [-2.5],
       [-1.5],
       [-0.5],
       [ 0.5],
       [ 1.5],
       [ 2.5],
       [ 3.5],
       [ 4.5]])
```



### Steps/Code to Reproduce

```
from sklearn.decomposition import PCA

x= np.array([1,2,3,4,5,6,7,8,9,10.]).reshape(-1,1).astype('float64')

p = PCA().fit_transform(x)
p
```

### Expected Results

```
array([[-4.5],
       [-3.5],
       [-2.5],
       [-1.5],
       [-0.5],
       [ 0.5],
       [ 1.5],
       [ 2.5],
       [ 3.5],
       [ 4.5]])
```

### Actual Results

```
array([[ 4.5],
       [ 3.5],
       [ 2.5],
       [ 1.5],
       [ 0.5],
       [-0.5],
       [-1.5],
       [-2.5],
       [-3.5],
       [-4.5]])
```

### Versions

```shell
System:
    python: 3.11.4 | packaged by Anaconda, Inc. | (main, Jul  5 2023, 13:47:18) [MSC v.1916 64 bit (AMD64)]
executable: e:\Users\***\miniconda3\python.exe
   machine: Windows-10-10.0.22621-SP0

Python dependencies:
      sklearn: 1.3.0
          pip: 23.2.1
   setuptools: 68.0.0
        numpy: 1.24.3
        scipy: 1.11.1
       Cython: None
       pandas: 2.0.3
   matplotlib: 3.7.1
       joblib: 1.2.0
threadpoolctl: 2.2.0

Built with OpenMP: True

threadpoolctl info:
       filepath: E:\Users\***\miniconda3\Library\bin\mkl_rt.2.dll
         prefix: mkl_rt
       user_api: blas
   internal_api: mkl
        version: 2023.1-Product
    num_threads: 8
threading_layer: intel

       filepath: E:\Users\***\miniconda3\vcomp140.dll
         prefix: vcomp
       user_api: openmp
   internal_api: openmp
        version: None
    num_threads: 16

       filepath: E:\Users\***\miniconda3\Library\bin\libiomp5md.dll
         prefix: libiomp
       user_api: openmp
   internal_api: openmp
        version: None
    num_threads: 16
```

COMMENT:
Thanks a lot. Maybe someone else with a Windows machine can try and reproduce this or has an idea why this happens

Labels: Bug
sklearn PCA rotates a single vector

### Describe the bug

The issue we recently discovered is that sklearn PCA rotates the input when only a single variable is fed into the model.  

I am aware there are infinite rotations when there is a single vector fed into the model, however, the output from PCA should intuitively make sense. So I suggest hard coding this scenario (which I guess already done in R)


### Steps/Code to Reproduce
```python
import numpy as np
from sklearn.decomposition import PCA

x = np.array([1,2,3,4,5,6,7,8,9,10.]).reshape(-1,1).astype('float64')

p = PCA().fit_transform(x)
p
```
### output:
```
array([[ 4.5],
       [ 3.5],
       [ 2.5],
       [ 1.5],
       [ 0.5],
       [-0.5],
       [-1.5],
       [-2.5],
       [-3.5],
       [-4.5]])
```

as we see here the value 4.5 is corresponding to the smallest value in the set (1) and the value -4.5 is corresponding to the highest value in the input set (10).

### Expected Results:
```
array([[-4.5],
       [-3.5],
       [-2.5],
       [-1.5],
       [-0.5],
       [ 0.5],
       [ 1.5],
       [ 2.5],
       [ 3.5],
       [ 4.5]])
```



### Steps/Code to Reproduce

```
from sklearn.decomposition import PCA

x= np.array([1,2,3,4,5,6,7,8,9,10.]).reshape(-1,1).astype('float64')

p = PCA().fit_transform(x)
p
```

### Expected Results

```
array([[-4.5],
       [-3.5],
       [-2.5],
       [-1.5],
       [-0.5],
       [ 0.5],
       [ 1.5],
       [ 2.5],
       [ 3.5],
       [ 4.5]])
```

### Actual Results

```
array([[ 4.5],
       [ 3.5],
       [ 2.5],
       [ 1.5],
       [ 0.5],
       [-0.5],
       [-1.5],
       [-2.5],
       [-3.5],
       [-4.5]])
```

### Versions

```shell
System:
    python: 3.11.4 | packaged by Anaconda, Inc. | (main, Jul  5 2023, 13:47:18) [MSC v.1916 64 bit (AMD64)]
executable: e:\Users\***\miniconda3\python.exe
   machine: Windows-10-10.0.22621-SP0

Python dependencies:
      sklearn: 1.3.0
          pip: 23.2.1
   setuptools: 68.0.0
        numpy: 1.24.3
        scipy: 1.11.1
       Cython: None
       pandas: 2.0.3
   matplotlib: 3.7.1
       joblib: 1.2.0
threadpoolctl: 2.2.0

Built with OpenMP: True

threadpoolctl info:
       filepath: E:\Users\***\miniconda3\Library\bin\mkl_rt.2.dll
         prefix: mkl_rt
       user_api: blas
   internal_api: mkl
        version: 2023.1-Product
    num_threads: 8
threading_layer: intel

       filepath: E:\Users\***\miniconda3\vcomp140.dll
         prefix: vcomp
       user_api: openmp
   internal_api: openmp
        version: None
    num_threads: 16

       filepath: E:\Users\***\miniconda3\Library\bin\libiomp5md.dll
         prefix: libiomp
       user_api: openmp
   internal_api: openmp
        version: None
    num_threads: 16
```

COMMENT:
I can reproduce by spotting that you installed MKL as a blas library.
It can be reproduced with the following environment.

```
mamba create --name xxx python=3.11 "blas=*=*mkl" mkl scipy=1.11.1 numpy=1.24.3 scikit-learn
```

Labels: Bug
Diagrams displayed using dark mode in light mode editor/notebook

I saw a couple of time that the dark mode to display the diagram is activated in my light mode editor or notebook:

![image](https://github.com/scikit-learn/scikit-learn/assets/7454015/f0f6cb65-14d4-4501-b45a-6a0732f7f5c0)


I did not follow the pull-request adding this feature and thus I was wondering if this is an expected behaviour or a bug. It is quite surprising on my hand (as a user).

ping @betatim @adrinjalali

COMMENT:
My understanding of `@media (prefers-color-scheme: dark)` (from `_estimator_html_repr.py`) is that it queries your browser about your preference regarding dark/light mode. This is from https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme.

So my guess is that your OS is set to "dark mode", which means the browser reports "dark" for `prefers-color-scheme`. Did you configure your OS (or browser?) to use dark mode? If yes, I think this is the explanation for why you get dark mode diagrams. And my guess would be that the notebook viewer/editor does not respect the OS setting/you configured it to always be in light mode.

One problem we have is that in the PR that added the dark mode thing we could not work out a way to query the light/dark mode preference of the notebook viewer. I think there is/will be a way to query Jupyter Lab, but not Jupyter Notebook and presumably the way to query VS Code would be yet another different way. This means that right now users who have conflicting OS and notebook viewer dark/light mode settings get a "mixed" experience.

An option we discussed is to introduce a new config flag in scikit-learn that would let you set dark/light mode. I dislike that option because it would be a setting in the code, not a config file. As this is a "user's preference" I don't think you should have it in code. So maybe an environment variable or config file? But with this discussion we open a whole new can of worms.

Labels: frontend, module:base
Diagrams displayed using dark mode in light mode editor/notebook

I saw a couple of time that the dark mode to display the diagram is activated in my light mode editor or notebook:

![image](https://github.com/scikit-learn/scikit-learn/assets/7454015/f0f6cb65-14d4-4501-b45a-6a0732f7f5c0)


I did not follow the pull-request adding this feature and thus I was wondering if this is an expected behaviour or a bug. It is quite surprising on my hand (as a user).

ping @betatim @adrinjalali

COMMENT:
Somehow the ideal solution (for me) would be to come up with a colour (or lack of colour) scheme for the diagrams that "just works" both in dark and light mode. I unfortunately don't (yet) know how to achieve that.

My best idea is to use ideas people use for labels on maps. For example using a dark colour for "Landesmuseum Zurich" which is nice on a light background and also outlining it with a light colour so you can still read it when it is over a dark background (like the river). Or the green colour for the park label, which has a white outline to make it stand out from the green background that is the park.

<img width="189" alt="Screenshot 2023-10-19 at 10 17 47" src="https://github.com/scikit-learn/scikit-learn/assets/1448859/8bc8b6a3-f1a5-4f49-9d80-13186af6b60f">

Labels: frontend, module:base
Diagrams displayed using dark mode in light mode editor/notebook

I saw a couple of time that the dark mode to display the diagram is activated in my light mode editor or notebook:

![image](https://github.com/scikit-learn/scikit-learn/assets/7454015/f0f6cb65-14d4-4501-b45a-6a0732f7f5c0)


I did not follow the pull-request adding this feature and thus I was wondering if this is an expected behaviour or a bug. It is quite surprising on my hand (as a user).

ping @betatim @adrinjalali

COMMENT:
I agree with most of the color scheme being compatible in both dark and light mode. As you mentioned in discord, #26616 might help in this direction. Then, I can think of a potential hack where the background and foreground color would use the theme of notebooks/vs-code and fallback to the OS. I will open a PR. On problem is that I can only infer how it works in notebooks and vs-code but I have no idea how other IDE will work.

Labels: frontend, module:base
Diagrams displayed using dark mode in light mode editor/notebook

I saw a couple of time that the dark mode to display the diagram is activated in my light mode editor or notebook:

![image](https://github.com/scikit-learn/scikit-learn/assets/7454015/f0f6cb65-14d4-4501-b45a-6a0732f7f5c0)


I did not follow the pull-request adding this feature and thus I was wondering if this is an expected behaviour or a bug. It is quite surprising on my hand (as a user).

ping @betatim @adrinjalali

COMMENT:
With #26616 merged this is what things look like for me:

<img width="474" alt="Screenshot 2023-10-25 at 09 17 29" src="https://github.com/scikit-learn/scikit-learn/assets/1448859/02aefc13-a9d4-4800-8002-11abcc24050f">


<img width="633" alt="Screenshot 2023-10-25 at 09 16 33" src="https://github.com/scikit-learn/scikit-learn/assets/1448859/53c80970-45e5-4d2c-b22f-fa7116dad8b4">

I'd say this is pretty good for dark/light mode compatibility. n.b. I switched between dark/light mode using the jupyter lab preferences (couldn't quickly find the button to switch my OS :-/).

Labels: frontend, module:base
Diagrams displayed using dark mode in light mode editor/notebook

I saw a couple of time that the dark mode to display the diagram is activated in my light mode editor or notebook:

![image](https://github.com/scikit-learn/scikit-learn/assets/7454015/f0f6cb65-14d4-4501-b45a-6a0732f7f5c0)


I did not follow the pull-request adding this feature and thus I was wondering if this is an expected behaviour or a bug. It is quite surprising on my hand (as a user).

ping @betatim @adrinjalali

COMMENT:
This has been addressed.

Labels: frontend, module:base
Cython: Use boundscheck(False) for faster access

When building scikit-learn on the Windows CI (with cython 0.29.36), I see many lines such as:

```
warning: sklearn\cluster\_k_means_lloyd.pyx:403:52: Use boundscheck(False) for faster access
```

See for instance: https://dev.azure.com/scikit-learn/scikit-learn/_build/results?buildId=60160&view=logs&j=0238e32a-2fbb-5be1-f782-cfff4ef2924e&t=f063c7d0-643d-578d-31b3-bc7abb593dec


This seem very fishy to me. This warning does not show up in the Linux CI build logs so it might be platform specific.

/cc @jjerphan @Micky774 @jeremiedbb

COMMENT:
Is this line not windows friendly ? https://github.com/scikit-learn/scikit-learn/blob/eadd9a0c4b9fd3cfa3039ccaa5e54dd5b11c4e29/sklearn/_build_utils/__init__.py#L67-L69

Labels: Performance, cython
Cython: Use boundscheck(False) for faster access

When building scikit-learn on the Windows CI (with cython 0.29.36), I see many lines such as:

```
warning: sklearn\cluster\_k_means_lloyd.pyx:403:52: Use boundscheck(False) for faster access
```

See for instance: https://dev.azure.com/scikit-learn/scikit-learn/_build/results?buildId=60160&view=logs&j=0238e32a-2fbb-5be1-f782-cfff4ef2924e&t=f063c7d0-643d-578d-31b3-bc7abb593dec


This seem very fishy to me. This warning does not show up in the Linux CI build logs so it might be platform specific.

/cc @jjerphan @Micky774 @jeremiedbb

COMMENT:
Oh actually this is on purpose: https://github.com/scikit-learn/scikit-learn/blob/e5c966e788f5b23425005100a60acbce6b0fa814/azure-pipelines.yml#L319

Labels: Performance, cython
Cython: Use boundscheck(False) for faster access

When building scikit-learn on the Windows CI (with cython 0.29.36), I see many lines such as:

```
warning: sklearn\cluster\_k_means_lloyd.pyx:403:52: Use boundscheck(False) for faster access
```

See for instance: https://dev.azure.com/scikit-learn/scikit-learn/_build/results?buildId=60160&view=logs&j=0238e32a-2fbb-5be1-f782-cfff4ef2924e&t=f063c7d0-643d-578d-31b3-bc7abb593dec


This seem very fishy to me. This warning does not show up in the Linux CI build logs so it might be platform specific.

/cc @jjerphan @Micky774 @jeremiedbb

COMMENT:
Context: https://github.com/scikit-learn/scikit-learn/pull/24438

I think we can close this issue.

Labels: Performance, cython
Cython: Use boundscheck(False) for faster access

When building scikit-learn on the Windows CI (with cython 0.29.36), I see many lines such as:

```
warning: sklearn\cluster\_k_means_lloyd.pyx:403:52: Use boundscheck(False) for faster access
```

See for instance: https://dev.azure.com/scikit-learn/scikit-learn/_build/results?buildId=60160&view=logs&j=0238e32a-2fbb-5be1-f782-cfff4ef2924e&t=f063c7d0-643d-578d-31b3-bc7abb593dec


This seem very fishy to me. This warning does not show up in the Linux CI build logs so it might be platform specific.

/cc @jjerphan @Micky774 @jeremiedbb

COMMENT:
Alright. Sorry for the noise. I forgot about this. I will push an extra comment in the yaml file.

Labels: Performance, cython
Add a version of `GenericUnivariateSelect`/`SelectPercentile`/`SelectKBest` that allows input of X with missing values and `y=None`.

### Describe the workflow you want to enable

- Select features by the percentage of missing values of X
- Select features only by statistical properties of X before y is available

### Describe your proposed solution

Create a version with weaker X, y checks.

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

1.
```python
class LooseGenericUnivariateSelect(GenericUnivariateSelect):
    def fit(self, X: Any, y: Any = None) -> Self:
        y = np.ones(X.shape[0])
        return super().fit(X, y)
    
    def _validate_data(self, X, y=None, *args, **kwargs):
        kwargs["force_all_finite"] = False
        kwargs.pop("multi_output", None)
        return super()._validate_data(X, y, *args, **kwargs)
    
    def _more_tags(self):
        return {"requires_y": False, "allow_nan": True}
```
Not sure if this code works properly.
2.
Bother to create an estimator that outputs the desired function in `feature_importance_` and use `SelectFromModel`

### Additional context

_No response_

COMMENT:
Thanks for creating the issue. Could you add a bit more context on use-cases where it would be useful to have this and maybe examples in the wild where this is being used. This will help to decide if we want to include this in scikit-learn.

Labels: New Feature