Talip7/scikit-learn-issues-multilabel huggingface dataset:
Yeo-Johnson Power Transformer gives Numpy warning (and raises scipy.optimize._optimize.BracketError in some cases)

### Describe the bug

When I use a power transformer with yeo-johnson method I get this warning in numpy:

`../lib/python3.10/site-packages/numpy/core/_methods.py:235: RuntimeWarning: overflow encountered in multiply`

Strangely I can't surpress this warning with filter.warnings()

**Tl;dr: The eroor seems to appear when multiple instances of the transformer are called, in this example because n_jobs=2 is set in the preprocessor. But the bug also appears with n_jobs=1 when you call this preprocessor in a grid search for example.**

### Steps/Code to Reproduce

The following code snippet will raise a warning:

```python
import numpy as np
from sklearn.preprocessing import PowerTransformer

rng = np.random.default_rng(0)
X = rng.exponential(size=(50,))
X -= X.max()
X = -X
X += 100
X = X.reshape(-1, 1)

method = "yeo-johnson"
transformer = PowerTransformer(method=method, standardize=False)
transformer.fit_transform(X)
```

### Expected Results

No Warnings

### Actual Results
```pytb
/Users/glemaitre/mambaforge/envs/dev/lib/python3.8/site-packages/numpy/core/_methods.py:233: RuntimeWarning: overflow encountered in multiply
  x = um.multiply(x, x, out=x)

```

### Versions

```shell
System:
    python: 3.8.12 | packaged by conda-forge | (default, Sep 16 2021, 01:38:21)  [Clang 11.1.0 ]
executable: /Users/glemaitre/mambaforge/envs/dev/bin/python
   machine: macOS-12.3.1-arm64-arm-64bit

Python dependencies:
      sklearn: 1.2.dev0
          pip: 21.3
   setuptools: 58.2.0
        numpy: 1.21.6
        scipy: 1.8.0
       Cython: 0.29.24
       pandas: 1.4.2
   matplotlib: 3.4.3
       joblib: 1.0.1
threadpoolctl: 2.2.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /Users/glemaitre/mambaforge/envs/dev/lib/libopenblas_vortexp-r0.3.18.dylib
        version: 0.3.18
threading_layer: openmp
   architecture: VORTEX
    num_threads: 8

       user_api: openmp
   internal_api: openmp
         prefix: libomp
       filepath: /Users/glemaitre/mambaforge/envs/dev/lib/libomp.dylib
        version: None
    num_threads: 8
```

COMMENT:
#26308 together with the upcoming scipy 1.12 will resolve this issue.

Labels: Bug, module:preprocessing
Yeo-Johnson Power Transformer gives Numpy warning (and raises scipy.optimize._optimize.BracketError in some cases)

### Describe the bug

When I use a power transformer with yeo-johnson method I get this warning in numpy:

`../lib/python3.10/site-packages/numpy/core/_methods.py:235: RuntimeWarning: overflow encountered in multiply`

Strangely I can't surpress this warning with filter.warnings()

**Tl;dr: The eroor seems to appear when multiple instances of the transformer are called, in this example because n_jobs=2 is set in the preprocessor. But the bug also appears with n_jobs=1 when you call this preprocessor in a grid search for example.**

### Steps/Code to Reproduce

The following code snippet will raise a warning:

```python
import numpy as np
from sklearn.preprocessing import PowerTransformer

rng = np.random.default_rng(0)
X = rng.exponential(size=(50,))
X -= X.max()
X = -X
X += 100
X = X.reshape(-1, 1)

method = "yeo-johnson"
transformer = PowerTransformer(method=method, standardize=False)
transformer.fit_transform(X)
```

### Expected Results

No Warnings

### Actual Results
```pytb
/Users/glemaitre/mambaforge/envs/dev/lib/python3.8/site-packages/numpy/core/_methods.py:233: RuntimeWarning: overflow encountered in multiply
  x = um.multiply(x, x, out=x)

```

### Versions

```shell
System:
    python: 3.8.12 | packaged by conda-forge | (default, Sep 16 2021, 01:38:21)  [Clang 11.1.0 ]
executable: /Users/glemaitre/mambaforge/envs/dev/bin/python
   machine: macOS-12.3.1-arm64-arm-64bit

Python dependencies:
      sklearn: 1.2.dev0
          pip: 21.3
   setuptools: 58.2.0
        numpy: 1.21.6
        scipy: 1.8.0
       Cython: 0.29.24
       pandas: 1.4.2
   matplotlib: 3.4.3
       joblib: 1.0.1
threadpoolctl: 2.2.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /Users/glemaitre/mambaforge/envs/dev/lib/libopenblas_vortexp-r0.3.18.dylib
        version: 0.3.18
threading_layer: openmp
   architecture: VORTEX
    num_threads: 8

       user_api: openmp
   internal_api: openmp
         prefix: libomp
       filepath: /Users/glemaitre/mambaforge/envs/dev/lib/libomp.dylib
        version: None
    num_threads: 8
```

COMMENT:
Closed by #31227.

Labels: Bug, module:preprocessing
Problem with maximal `int` value in `train_test_split`

### Describe the bug

It seems that above ~10^9, ints are not accepted and `train_test_split` spits out some nonsense values ... This occurs only if I pass numpy arrays, with lists all seems to work fine.

I have been able to circumvent it by just dividing the values by 1000, but I suppose that's not exactly what we'd like to do:
![image](https://user-images.githubusercontent.com/25057504/167442839-3a8f1f19-02c3-4c92-94eb-1c7e79858b29.png)

Fyi: I do not scale this variable, since it's not really a feature, it's just a quantity I use to compute weights.

### Steps/Code to Reproduce

```
data_arr = np.array([1,2915000000,  4890000000, 14145000000,2915000000,  4890000000, 14145000000,2915000000,  4890000000, 14145000000,1])
class_arr = np.array([1,1,2,3,1,2,3,1,2,3,2])
np.unique(data_arr)
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(
    data_arr, 
    class_arr, 
    test_size=0.3, 
    random_state=5, 
    shuffle=True, 
    stratify=class_arr
)
np.unique(x_train)
```

### Expected Results

The values passed to `train_test_split` should not be modified ...

### Actual Results

They are modified if they are too large:
![image](https://user-images.githubusercontent.com/25057504/167442456-3c3ec451-9625-49fd-af6a-5c356c478486.png)

### Versions

```shell
System:
    python: 3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)]
executable: E:\Anaconda3\python.exe
   machine: Windows-10-10.0.19043-SP0

Python dependencies:
          pip: 21.2.4
   setuptools: 61.2.0
      sklearn: 1.0.2
        numpy: 1.22.3
        scipy: 1.8.0
       Cython: None
       pandas: 1.4.2
   matplotlib: 3.3.1
       joblib: 1.1.0
threadpoolctl: 3.1.0

Built with OpenMP: True
```

COMMENT:
Can you see what happens when you set the dtype to `np.int64` explicity in `data_arr`:

```python
data_arr = np.array([1, 2915000000, 4890000000, 14145000000,
    2915000000, 4890000000, 14145000000,2915000000, 
    4890000000, 14145000000, 1], dtype=np.int64)
...
```

Labels: Bug, module:model_selection
Problem with maximal `int` value in `train_test_split`

### Describe the bug

It seems that above ~10^9, ints are not accepted and `train_test_split` spits out some nonsense values ... This occurs only if I pass numpy arrays, with lists all seems to work fine.

I have been able to circumvent it by just dividing the values by 1000, but I suppose that's not exactly what we'd like to do:
![image](https://user-images.githubusercontent.com/25057504/167442839-3a8f1f19-02c3-4c92-94eb-1c7e79858b29.png)

Fyi: I do not scale this variable, since it's not really a feature, it's just a quantity I use to compute weights.

### Steps/Code to Reproduce

```
data_arr = np.array([1,2915000000,  4890000000, 14145000000,2915000000,  4890000000, 14145000000,2915000000,  4890000000, 14145000000,1])
class_arr = np.array([1,1,2,3,1,2,3,1,2,3,2])
np.unique(data_arr)
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(
    data_arr, 
    class_arr, 
    test_size=0.3, 
    random_state=5, 
    shuffle=True, 
    stratify=class_arr
)
np.unique(x_train)
```

### Expected Results

The values passed to `train_test_split` should not be modified ...

### Actual Results

They are modified if they are too large:
![image](https://user-images.githubusercontent.com/25057504/167442456-3c3ec451-9625-49fd-af6a-5c356c478486.png)

### Versions

```shell
System:
    python: 3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)]
executable: E:\Anaconda3\python.exe
   machine: Windows-10-10.0.19043-SP0

Python dependencies:
          pip: 21.2.4
   setuptools: 61.2.0
      sklearn: 1.0.2
        numpy: 1.22.3
        scipy: 1.8.0
       Cython: None
       pandas: 1.4.2
   matplotlib: 3.3.1
       joblib: 1.1.0
threadpoolctl: 3.1.0

Built with OpenMP: True
```

COMMENT:
With a slightly older version of `numpy` it actually seems to work fine, it just assumes `dtype=np.int64` by itself.

```
System:
    python: 3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)]
executable: E:\Anaconda3\python.exe
   machine: Windows-10-10.0.19043-SP0

Python dependencies:
          pip: 21.2.4
   setuptools: 61.2.0
      sklearn: 1.0.2
        numpy: 1.20.3
        scipy: 1.8.1
       Cython: None
       pandas: 1.4.2
   matplotlib: 3.5.1
       joblib: 1.1.0
threadpoolctl: 3.1.0

Built with OpenMP: True
```

Labels: Bug, module:model_selection
Spurious warning with DecisionBoundaryPlot

The following snippet will raise a warning regarding feature names

```python
# %%
from sklearn.datasets import load_iris

iris = load_iris(as_frame=True)
X = iris.data[["sepal width (cm)", "petal width (cm)"]]
y = iris.target

# %%
from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(
    X, y, random_state=42
)

# %%
from sklearn.linear_model import LogisticRegression

model = LogisticRegression().fit(X_train, y_train)

# %%
from sklearn.inspection import DecisionBoundaryDisplay

display = DecisionBoundaryDisplay.from_estimator(model, X_train, alpha=0.5)
scatter = display.ax_.scatter(
    X_train["sepal width (cm)"], X_train["petal width (cm)"], c=y_train, edgecolor="k"
)
display.ax_.legend(scatter.legend_elements()[0], iris.target_names)
```

```pytb
/Users/glemaitre/Documents/packages/scikit-learn/sklearn/base.py:450: UserWarning: X does not have valid feature names, but LogisticRegression was fitted with feature names
  warnings.warn(
```

It is not a regression but the warning should not be raised. I think that we should correct this for 1.1 release.

COMMENT:
The problematic part is the following:

https://github.com/scikit-learn/scikit-learn/blob/5e64d3a0aff5e49955536f7416827f8aa479a006/sklearn/inspection/_plot/decision_boundary.py#L293-L299

We always create a NumPy array even if a dataframe was given at `fit`.
We should recreate a dataframe.

One trick would be to do:

```python
if hasattr(X, "iloc"):
    X_meshgrid = X.iloc[[], :].copy()
    X_meshgrid.iloc[:, 0] = xx0.ravel()
    X_meshgrid.iloc[:, 1] = xx1.ravel()
else:
    X_meshgrid = np.c_[xx0.ravel(), xx1.ravel()]
```

Labels: Needs Triage
Spurious warning with DecisionBoundaryPlot

The following snippet will raise a warning regarding feature names

```python
# %%
from sklearn.datasets import load_iris

iris = load_iris(as_frame=True)
X = iris.data[["sepal width (cm)", "petal width (cm)"]]
y = iris.target

# %%
from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(
    X, y, random_state=42
)

# %%
from sklearn.linear_model import LogisticRegression

model = LogisticRegression().fit(X_train, y_train)

# %%
from sklearn.inspection import DecisionBoundaryDisplay

display = DecisionBoundaryDisplay.from_estimator(model, X_train, alpha=0.5)
scatter = display.ax_.scatter(
    X_train["sepal width (cm)"], X_train["petal width (cm)"], c=y_train, edgecolor="k"
)
display.ax_.legend(scatter.legend_elements()[0], iris.target_names)
```

```pytb
/Users/glemaitre/Documents/packages/scikit-learn/sklearn/base.py:450: UserWarning: X does not have valid feature names, but LogisticRegression was fitted with feature names
  warnings.warn(
```

It is not a regression but the warning should not be raised. I think that we should correct this for 1.1 release.

COMMENT:
/take

Labels: Needs Triage
Use `cimport numpy as cnp` in Cython files for NumPy C API

I propose using `cnp` to reference NumPy's C API in Cython files. This pattern is [adapted in pandas](https://github.com/pandas-dev/pandas/blob/422e92ab29ea279c95d212124d9ffe5988c34ab6/pandas/_libs/lib.pyx#L33-L35) and it looks reasonable. The idea is to use `np` for the Python API and `cnp` for C API:

```python
import numpy as np

cimport numpy as cnp
cnp.import_array()
```

COMMENT:
+1 on this. I propose to do it file by file in separate PRs.

Labels: cython, Refactor
Use `cimport numpy as cnp` in Cython files for NumPy C API

I propose using `cnp` to reference NumPy's C API in Cython files. This pattern is [adapted in pandas](https://github.com/pandas-dev/pandas/blob/422e92ab29ea279c95d212124d9ffe5988c34ab6/pandas/_libs/lib.pyx#L33-L35) and it looks reasonable. The idea is to use `np` for the Python API and `cnp` for C API:

```python
import numpy as np

cimport numpy as cnp
cnp.import_array()
```

COMMENT:
+1 on this too. If it is okay, I will make a list with all the files where we have to apply this change.

Labels: cython, Refactor
Use `cimport numpy as cnp` in Cython files for NumPy C API

I propose using `cnp` to reference NumPy's C API in Cython files. This pattern is [adapted in pandas](https://github.com/pandas-dev/pandas/blob/422e92ab29ea279c95d212124d9ffe5988c34ab6/pandas/_libs/lib.pyx#L33-L35) and it looks reasonable. The idea is to use `np` for the Python API and `cnp` for C API:

```python
import numpy as np

cimport numpy as cnp
cnp.import_array()
```

COMMENT:
+1 as well.

Indeed I was discussing the import ambuity with @jeremiedbb IRL last week.

Labels: cython, Refactor
Use `cimport numpy as cnp` in Cython files for NumPy C API

I propose using `cnp` to reference NumPy's C API in Cython files. This pattern is [adapted in pandas](https://github.com/pandas-dev/pandas/blob/422e92ab29ea279c95d212124d9ffe5988c34ab6/pandas/_libs/lib.pyx#L33-L35) and it looks reasonable. The idea is to use `np` for the Python API and `cnp` for C API:

```python
import numpy as np

cimport numpy as cnp
cnp.import_array()
```

COMMENT:
No module left. I would say that we can close this issue.

Labels: cython, Refactor
Use `cimport numpy as cnp` in Cython files for NumPy C API

I propose using `cnp` to reference NumPy's C API in Cython files. This pattern is [adapted in pandas](https://github.com/pandas-dev/pandas/blob/422e92ab29ea279c95d212124d9ffe5988c34ab6/pandas/_libs/lib.pyx#L33-L35) and it looks reasonable. The idea is to use `np` for the Python API and `cnp` for C API:

```python
import numpy as np

cimport numpy as cnp
cnp.import_array()
```

COMMENT:
Nice work. Thanks to everyone. Closing.

Labels: cython, Refactor
Less greedy RFECV (1-S.E. Rule)

Current implementation of RFECV selects the number of features that achieve optimal score (e.g., accuracy, r2).
This can lead to a greedy behavior and i feel it would be useful to have a "One-standard-error" rule for selecting the number of features. This is feasible now that the `cv_results_` is returned instead of `grid_scores_`

For example. Looking at the [User Guide Example](https://scikit-learn.org/stable/auto_examples/feature_selection/plot_rfe_with_cross_validation.html#sphx-glr-auto-examples-feature-selection-plot-rfe-with-cross-validation-py), RFECV selects 6 features (maximum score) although it is easy to see that 3 features achieve a score within 1S.E. of the maximum score using error bars. These 3 features also coincide with the 3 informative features used in the simulation 


![class_rfecv](https://user-images.githubusercontent.com/25321020/166947385-1b801ccd-0430-476c-8bfc-147cc134a5b4.png)

Same goes for the Boston Dataset. RFECV selects 6 features (minimum MSE) but 4 features achieve performance within 1S.E.
![boston_rfecv](https://user-images.githubusercontent.com/25321020/166947665-edf59272-57db-4c87-a5e1-d27ca22f12f9.png)

In a real project with hundreds of features this approach could lead to a significant reduction of features with minimal effect on performance.

COMMENT:
Are you aware of any literature regarding the subject?

Labels: module:feature_selection, Needs Decision - Include Feature
Less greedy RFECV (1-S.E. Rule)

Current implementation of RFECV selects the number of features that achieve optimal score (e.g., accuracy, r2).
This can lead to a greedy behavior and i feel it would be useful to have a "One-standard-error" rule for selecting the number of features. This is feasible now that the `cv_results_` is returned instead of `grid_scores_`

For example. Looking at the [User Guide Example](https://scikit-learn.org/stable/auto_examples/feature_selection/plot_rfe_with_cross_validation.html#sphx-glr-auto-examples-feature-selection-plot-rfe-with-cross-validation-py), RFECV selects 6 features (maximum score) although it is easy to see that 3 features achieve a score within 1S.E. of the maximum score using error bars. These 3 features also coincide with the 3 informative features used in the simulation 


![class_rfecv](https://user-images.githubusercontent.com/25321020/166947385-1b801ccd-0430-476c-8bfc-147cc134a5b4.png)

Same goes for the Boston Dataset. RFECV selects 6 features (minimum MSE) but 4 features achieve performance within 1S.E.
![boston_rfecv](https://user-images.githubusercontent.com/25321020/166947665-edf59272-57db-4c87-a5e1-d27ca22f12f9.png)

In a real project with hundreds of features this approach could lead to a significant reduction of features with minimal effect on performance.

COMMENT:
A few quick quotes from

The Elements of statistical Learning:
page 61: "We have used the “one-standard-error” rule—we pick the most parsimonious model within
one standard error of the minimum (Section 7.10, page 244). Such a rule acknowledges the fact that the tradeoff curve is estimated with error, and hence takes a conservative approach."

page 244: "Often a “one-standard error” rule is used with cross-validation, in which we choose the most parsimonious model whose error is no more than one standard error above the error of the best model."

From Applied Predictive Modelling
page 75: "The “one-standard error”method for choosing simpler models finds the numerically optimal value and its corresponding standard error and then seeks the simplest model whose performance is within a single standard error of
the numerically best value. This procedure originated with classification and regression trees (Breiman et al. (1984) and Sects. 8.1 and 14.1)."

In addition, this is implemented in R's `caret` both for tuning and feature selection. I can dig up some more if needed.

Labels: module:feature_selection, Needs Decision - Include Feature
Less greedy RFECV (1-S.E. Rule)

Current implementation of RFECV selects the number of features that achieve optimal score (e.g., accuracy, r2).
This can lead to a greedy behavior and i feel it would be useful to have a "One-standard-error" rule for selecting the number of features. This is feasible now that the `cv_results_` is returned instead of `grid_scores_`

For example. Looking at the [User Guide Example](https://scikit-learn.org/stable/auto_examples/feature_selection/plot_rfe_with_cross_validation.html#sphx-glr-auto-examples-feature-selection-plot-rfe-with-cross-validation-py), RFECV selects 6 features (maximum score) although it is easy to see that 3 features achieve a score within 1S.E. of the maximum score using error bars. These 3 features also coincide with the 3 informative features used in the simulation 


![class_rfecv](https://user-images.githubusercontent.com/25321020/166947385-1b801ccd-0430-476c-8bfc-147cc134a5b4.png)

Same goes for the Boston Dataset. RFECV selects 6 features (minimum MSE) but 4 features achieve performance within 1S.E.
![boston_rfecv](https://user-images.githubusercontent.com/25321020/166947665-edf59272-57db-4c87-a5e1-d27ca22f12f9.png)

In a real project with hundreds of features this approach could lead to a significant reduction of features with minimal effect on performance.

COMMENT:
To be clear, i am just proposing that there should be some king of 'strategy/criterion' argument for RFECV that defaults to 'optimal' to be consistent with current implementation, but allows for the one-standard-error-rule.

Here is another example using the California housing data. RFECV selects 26 features, but 9 of them would get you a performance within 1S.E.
![california_housing](https://user-images.githubusercontent.com/25321020/167105232-e16588c8-4192-4149-bd99-76993cf349ee.png)

Labels: module:feature_selection, Needs Decision - Include Feature
randomized_svd uses all available cpus

### Describe the bug

When i run randomized_svd it uses all available cpus 

### Steps/Code to Reproduce

```
from sklearn.utils.extmath import randomized_svd

a = np.random.rand(1000000,2000)
output = randomized_svd(a, n_components=20, flip_sign=True, n_iter=20, random_state=42)
```

### Expected Results

one thread

### Actual Results

no

### Versions

```shell
System:
    python: 3.7.7 (default, Mar 26 2020, 15:48:22)  [GCC 7.3.0]
executable: /opt/miniconda/bin/python
   machine: Linux-4.15.0-163-generic-x86_64-with-debian-buster-sid

Python dependencies:
          pip: 22.0.4
   setuptools: 56.2.0
      sklearn: 1.0.1
        numpy: 1.20.3
        scipy: 1.6.3
       Cython: None
       pandas: 1.3.5
   matplotlib: 3.4.3
       joblib: 1.1.0
threadpoolctl: 3.1.0

Built with OpenMP: True
```

COMMENT:
`randomized_svd` uses SciPy's `linalg.svd` which uses multiple cores by default. If you want to limit the number of cores, you can use `threadpoolctl`:

```python
import numpy as np
from threadpoolctl import threadpool_limits
from sklearn.utils.extmath import randomized_svd

a = np.random.rand(400_000, 100)

with threadpool_limits(limits=1, user_api="blas"):
    output = randomized_svd(
        a, n_components=20, flip_sign=True, n_iter=20, random_state=42
    )
```

The behavior of using multiple cores for linalg is inherited from SciPy and not a specific issue with scikit-learn.

Labels: Bug, Needs Triage
i need some help with this pyinstaller

### Describe the bug

when i do the download for pyinstaller it says ERROR

### Steps/Code to Reproduce

pip install pyinstaller
Collecting pyinstaller
  Using cached pyinstaller-5.0.1-py3-none-win_amd64.whl (2.0 MB)
Requirement already satisfied: setuptools in c:\program files\windowsapps\pythonsoftwarefoundation.python.3.10_3.10.1264.0_x64__qbz5n2kfra8p0\lib\site-packages (from pyinstaller) (58.1.0)
Collecting pywin32-ctypes>=0.2.0
  Using cached pywin32_ctypes-0.2.0-py2.py3-none-any.whl (28 kB)
Collecting pefile>=2017.8.1
  Using cached pefile-2021.9.3.tar.gz (72 kB)
  Preparing metadata (setup.py) ...   ERROR: Error [WinError 5] Access is denied while executing command python setup.py egg_info
error
ERROR: Could not install packages due to an OSError: [WinError 5] Access is denied
Check the permissions.

### Expected Results

its just supposed to download successfully 

### Actual Results

says ERROR

### Versions

```shell
idk
```

COMMENT:
I am closing this issue because this issue tracker is for bugs related to scikit-learn.

Labels: Bug, Needs Triage