Talip7/scikit-learn-issues-multilabel huggingface dataset:
MLPEstimator do not report the proper `n_iter_` after successive call of `fit`

### Describe the bug

It seems that `MLPRegressor` and `MLPClassifier` does not take into account `max_iter` with `warm_start`.

### Steps/Code to Reproduce


```python
model = MLPRegressor(warm_start=True, early_stopping=True, max_iter=10)
model.fit(X_iris, y_iris)
assert model.n_iter_ <= 10
model.set_params(max_iter=20)
model.fit(X_iris, y_iris)
assert model.n_iter_ <= 20
```

You can also try `MLPClassifier` which leads to over iterating.

### Expected Results

`n_iter_ <= 20`

### Actual Results

```pytb
    def test_xxx():
        model = MLPRegressor(warm_start=True, early_stopping=False, max_iter=10)
        model.fit(X_iris, y_iris)
        assert model.n_iter_ <= 10
        model.set_params(max_iter=20)
        model.fit(X_iris, y_iris)
>       assert model.n_iter_ <= 20
E       assert 30 <= 20
E        +  where 30 = MLPRegressor(max_iter=20, warm_start=True).n_iter_
```

### 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.6-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.5.0
   matplotlib: 3.4.3
       joblib: 1.2.0
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:
Just to confirmed that this is a bug because the above test would work with `RandomForest`.

Labels: Bug, module:neural_network
PCA crashes when fit to large array

### Describe the bug

When trying to fit a `PCA` model to a large dataset with `shape=(30000, 28000)`, the model fits for a bit more than 30 minutes using nearly all cores and then crashes out of python. I've confirmed that a dataset with `shape=(20000, 28000)` succeeds without issue. I watched both in `htop` and found memory usage to never exceed 30% available memory.

### Steps/Code to Reproduce

```python
import numpy as np
from sklearn import decomposition

data = np.random.randn(30000, 28000)
pca_model = decomposition.PCA(0.95, whiten=True)
pca_model.fit(data)
```

### Expected Results

The model should be fit without crashing out of python.

### Actual Results

```
free(): invalid size
Aborted (core dumped)
```

### Versions

```shell
System:
    python: 3.8.10 (default, Jun 22 2022, 20:18:18)  [GCC 9.4.0]
executable: /usr/local/bin/python
   machine: Linux-4.15.0-136-generic-x86_64-with-glibc2.29

Python dependencies:
      sklearn: 1.1.2
          pip: 20.2.4
   setuptools: 63.2.0
        numpy: 1.22.3
        scipy: 1.9.0
       Cython: None
       pandas: 1.4.2
   matplotlib: None
       joblib: 1.1.0
threadpoolctl: 3.1.0

Built with OpenMP: True

threadpoolctl info:
       user_api: openmp
   internal_api: openmp
         prefix: libgomp
       filepath: /home/container-user/.local/lib/python3.8/site-packages/scikit_learn.libs/libgomp-a34b3233.so.1.0.0
        version: None
    num_threads: 72

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /home/container-user/.local/lib/python3.8/site-packages/numpy.libs/libopenblas64_p-r0-2f7c42d4.3.18.so
        version: 0.3.18
threading_layer: pthreads
   architecture: SkylakeX
    num_threads: 64

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /home/container-user/.local/lib/python3.8/site-packages/scipy.libs/libopenblasp-r0-9f9f5dbc.3.18.so
        version: 0.3.18
threading_layer: pthreads
   architecture: SkylakeX
    num_threads: 64
```

COMMENT:
Since the core of `PCA` in this case is a call to `scipy.linalg.svd`, I tried replacing that with `numpy.linalg.svd` and that ran without issue. It seems this bug is a direct result of how scipy implemented `svd`.

[Line of code](https://github.com/scikit-learn/scikit-learn/blob/main/sklearn/decomposition/_pca.py#L536)

Labels: Bug, module:decomposition
PCA crashes when fit to large array

### Describe the bug

When trying to fit a `PCA` model to a large dataset with `shape=(30000, 28000)`, the model fits for a bit more than 30 minutes using nearly all cores and then crashes out of python. I've confirmed that a dataset with `shape=(20000, 28000)` succeeds without issue. I watched both in `htop` and found memory usage to never exceed 30% available memory.

### Steps/Code to Reproduce

```python
import numpy as np
from sklearn import decomposition

data = np.random.randn(30000, 28000)
pca_model = decomposition.PCA(0.95, whiten=True)
pca_model.fit(data)
```

### Expected Results

The model should be fit without crashing out of python.

### Actual Results

```
free(): invalid size
Aborted (core dumped)
```

### Versions

```shell
System:
    python: 3.8.10 (default, Jun 22 2022, 20:18:18)  [GCC 9.4.0]
executable: /usr/local/bin/python
   machine: Linux-4.15.0-136-generic-x86_64-with-glibc2.29

Python dependencies:
      sklearn: 1.1.2
          pip: 20.2.4
   setuptools: 63.2.0
        numpy: 1.22.3
        scipy: 1.9.0
       Cython: None
       pandas: 1.4.2
   matplotlib: None
       joblib: 1.1.0
threadpoolctl: 3.1.0

Built with OpenMP: True

threadpoolctl info:
       user_api: openmp
   internal_api: openmp
         prefix: libgomp
       filepath: /home/container-user/.local/lib/python3.8/site-packages/scikit_learn.libs/libgomp-a34b3233.so.1.0.0
        version: None
    num_threads: 72

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /home/container-user/.local/lib/python3.8/site-packages/numpy.libs/libopenblas64_p-r0-2f7c42d4.3.18.so
        version: 0.3.18
threading_layer: pthreads
   architecture: SkylakeX
    num_threads: 64

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /home/container-user/.local/lib/python3.8/site-packages/scipy.libs/libopenblasp-r0-9f9f5dbc.3.18.so
        version: 0.3.18
threading_layer: pthreads
   architecture: SkylakeX
    num_threads: 64
```

COMMENT:
If the two `svd()` functions are equivalent, then I think what you found suggests this is an issue to take up with SciPy to understand why `numpy.linalg.svd` works but `scipy.linalg.svd` doesn't?

Labels: Bug, module:decomposition
PCA crashes when fit to large array

### Describe the bug

When trying to fit a `PCA` model to a large dataset with `shape=(30000, 28000)`, the model fits for a bit more than 30 minutes using nearly all cores and then crashes out of python. I've confirmed that a dataset with `shape=(20000, 28000)` succeeds without issue. I watched both in `htop` and found memory usage to never exceed 30% available memory.

### Steps/Code to Reproduce

```python
import numpy as np
from sklearn import decomposition

data = np.random.randn(30000, 28000)
pca_model = decomposition.PCA(0.95, whiten=True)
pca_model.fit(data)
```

### Expected Results

The model should be fit without crashing out of python.

### Actual Results

```
free(): invalid size
Aborted (core dumped)
```

### Versions

```shell
System:
    python: 3.8.10 (default, Jun 22 2022, 20:18:18)  [GCC 9.4.0]
executable: /usr/local/bin/python
   machine: Linux-4.15.0-136-generic-x86_64-with-glibc2.29

Python dependencies:
      sklearn: 1.1.2
          pip: 20.2.4
   setuptools: 63.2.0
        numpy: 1.22.3
        scipy: 1.9.0
       Cython: None
       pandas: 1.4.2
   matplotlib: None
       joblib: 1.1.0
threadpoolctl: 3.1.0

Built with OpenMP: True

threadpoolctl info:
       user_api: openmp
   internal_api: openmp
         prefix: libgomp
       filepath: /home/container-user/.local/lib/python3.8/site-packages/scikit_learn.libs/libgomp-a34b3233.so.1.0.0
        version: None
    num_threads: 72

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /home/container-user/.local/lib/python3.8/site-packages/numpy.libs/libopenblas64_p-r0-2f7c42d4.3.18.so
        version: 0.3.18
threading_layer: pthreads
   architecture: SkylakeX
    num_threads: 64

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /home/container-user/.local/lib/python3.8/site-packages/scipy.libs/libopenblasp-r0-9f9f5dbc.3.18.so
        version: 0.3.18
threading_layer: pthreads
   architecture: SkylakeX
    num_threads: 64
```

COMMENT:
I agree, but I figured it's worth leaving here since it's still causing a bug with a usable workaround.

Labels: Bug, module:decomposition
PCA crashes when fit to large array

### Describe the bug

When trying to fit a `PCA` model to a large dataset with `shape=(30000, 28000)`, the model fits for a bit more than 30 minutes using nearly all cores and then crashes out of python. I've confirmed that a dataset with `shape=(20000, 28000)` succeeds without issue. I watched both in `htop` and found memory usage to never exceed 30% available memory.

### Steps/Code to Reproduce

```python
import numpy as np
from sklearn import decomposition

data = np.random.randn(30000, 28000)
pca_model = decomposition.PCA(0.95, whiten=True)
pca_model.fit(data)
```

### Expected Results

The model should be fit without crashing out of python.

### Actual Results

```
free(): invalid size
Aborted (core dumped)
```

### Versions

```shell
System:
    python: 3.8.10 (default, Jun 22 2022, 20:18:18)  [GCC 9.4.0]
executable: /usr/local/bin/python
   machine: Linux-4.15.0-136-generic-x86_64-with-glibc2.29

Python dependencies:
      sklearn: 1.1.2
          pip: 20.2.4
   setuptools: 63.2.0
        numpy: 1.22.3
        scipy: 1.9.0
       Cython: None
       pandas: 1.4.2
   matplotlib: None
       joblib: 1.1.0
threadpoolctl: 3.1.0

Built with OpenMP: True

threadpoolctl info:
       user_api: openmp
   internal_api: openmp
         prefix: libgomp
       filepath: /home/container-user/.local/lib/python3.8/site-packages/scikit_learn.libs/libgomp-a34b3233.so.1.0.0
        version: None
    num_threads: 72

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /home/container-user/.local/lib/python3.8/site-packages/numpy.libs/libopenblas64_p-r0-2f7c42d4.3.18.so
        version: 0.3.18
threading_layer: pthreads
   architecture: SkylakeX
    num_threads: 64

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /home/container-user/.local/lib/python3.8/site-packages/scipy.libs/libopenblasp-r0-9f9f5dbc.3.18.so
        version: 0.3.18
threading_layer: pthreads
   architecture: SkylakeX
    num_threads: 64
```

COMMENT:
I met a similar bug, and I think it's caused by the [OpenBLAS](https://www.openblas.net/) used by NumPy and SciPy. 
In my case, the following steps can solve this issue:
1. Change NumPy to 1.21.5
2. Or, change SciPy to 1.8.0
3. Or, install NumPy using conda so that it uses MKL rather than OpenBlas

Labels: Bug, module:decomposition
PCA crashes when fit to large array

### Describe the bug

When trying to fit a `PCA` model to a large dataset with `shape=(30000, 28000)`, the model fits for a bit more than 30 minutes using nearly all cores and then crashes out of python. I've confirmed that a dataset with `shape=(20000, 28000)` succeeds without issue. I watched both in `htop` and found memory usage to never exceed 30% available memory.

### Steps/Code to Reproduce

```python
import numpy as np
from sklearn import decomposition

data = np.random.randn(30000, 28000)
pca_model = decomposition.PCA(0.95, whiten=True)
pca_model.fit(data)
```

### Expected Results

The model should be fit without crashing out of python.

### Actual Results

```
free(): invalid size
Aborted (core dumped)
```

### Versions

```shell
System:
    python: 3.8.10 (default, Jun 22 2022, 20:18:18)  [GCC 9.4.0]
executable: /usr/local/bin/python
   machine: Linux-4.15.0-136-generic-x86_64-with-glibc2.29

Python dependencies:
      sklearn: 1.1.2
          pip: 20.2.4
   setuptools: 63.2.0
        numpy: 1.22.3
        scipy: 1.9.0
       Cython: None
       pandas: 1.4.2
   matplotlib: None
       joblib: 1.1.0
threadpoolctl: 3.1.0

Built with OpenMP: True

threadpoolctl info:
       user_api: openmp
   internal_api: openmp
         prefix: libgomp
       filepath: /home/container-user/.local/lib/python3.8/site-packages/scikit_learn.libs/libgomp-a34b3233.so.1.0.0
        version: None
    num_threads: 72

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /home/container-user/.local/lib/python3.8/site-packages/numpy.libs/libopenblas64_p-r0-2f7c42d4.3.18.so
        version: 0.3.18
threading_layer: pthreads
   architecture: SkylakeX
    num_threads: 64

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /home/container-user/.local/lib/python3.8/site-packages/scipy.libs/libopenblasp-r0-9f9f5dbc.3.18.so
        version: 0.3.18
threading_layer: pthreads
   architecture: SkylakeX
    num_threads: 64
```

COMMENT:
Please fix.  A full PCA is crashing when the n_components = min( len(X), len(X.columns) )
Performing a PCA on a 224x224x3 color image for 80000 samples should not crash scikit-learn.  Scikit-learn navigates the crash 1/30 times

Labels: Bug, module:decomposition
add `feature_names_in_` attribute to `FeatureUnion`

### Describe the workflow you want to enable

The docs for `feature_names_in_` in the `sklearn.pipeline.Pipeline` say:

> feature_names_in_ : ndarray of shape (`n_features_in_`,)
        Names of features seen during :term:`fit`. Only defined if the
        underlying estimator exposes such an attribute when fit.

Several pipeline-friendly classes already have this attribute, e.g. `FunctionTransformer`, `LinearRegression`, `PCA`. It would be helpful if `FeatureUnion` also had this attribute.

### Describe your proposed solution

My proposed solution is to collect and store the `feature_names_in_` during fitting using the [`._check_feature_names(...)`](https://github.com/scikit-learn/scikit-learn/blob/36958fb240fbe435673a9e3c52e769f01f36bec0/sklearn/base.py#L405) method

```diff
    def fit(self, X, y=None):
        """Fit transformer by checking X.
        If ``validate`` is ``True``, ``X`` will be checked.
        Parameters
        ----------
        X : array-like, shape (n_samples, n_features)
            Input array.
        y : Ignored
            Not used, present here for API consistency by convention.
        Returns
        -------
        self : object
            FunctionTransformer class instance.
        """
        X = self._check_input(X, reset=True)
        if self.check_inverse and not (self.func is None or self.inverse_func is None):
            self._check_inverse_transform(X)
+       self._check_feature_names(X, reset=True)
        return self
```

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

I've considered at least three alternatives:

1. Let the user incorporate the `._check_feature_names(...)` method themselves
2. Add a `.setter` method to the `feature_names_in_` property
3. Iterate over the `transformers` in the `transformer_list` and get the `feature_names_in_` from each

### Additional context

This is essentially the same as calling `.columns` on the input data if it has a `.columns` attribute (i.e. `pandas.DataFrame`). However, it would be helpful in examining individual steps if this `FeatureUnion` is buried deep in a series of transformations.

COMMENT:
I am +1 on the proposal for always setting `feature_names_in_` in `FeatureUnion`. Do you want to open a PR for this change?

Labels: New Feature, module:pipeline
add `feature_names_in_` attribute to `FeatureUnion`

### Describe the workflow you want to enable

The docs for `feature_names_in_` in the `sklearn.pipeline.Pipeline` say:

> feature_names_in_ : ndarray of shape (`n_features_in_`,)
        Names of features seen during :term:`fit`. Only defined if the
        underlying estimator exposes such an attribute when fit.

Several pipeline-friendly classes already have this attribute, e.g. `FunctionTransformer`, `LinearRegression`, `PCA`. It would be helpful if `FeatureUnion` also had this attribute.

### Describe your proposed solution

My proposed solution is to collect and store the `feature_names_in_` during fitting using the [`._check_feature_names(...)`](https://github.com/scikit-learn/scikit-learn/blob/36958fb240fbe435673a9e3c52e769f01f36bec0/sklearn/base.py#L405) method

```diff
    def fit(self, X, y=None):
        """Fit transformer by checking X.
        If ``validate`` is ``True``, ``X`` will be checked.
        Parameters
        ----------
        X : array-like, shape (n_samples, n_features)
            Input array.
        y : Ignored
            Not used, present here for API consistency by convention.
        Returns
        -------
        self : object
            FunctionTransformer class instance.
        """
        X = self._check_input(X, reset=True)
        if self.check_inverse and not (self.func is None or self.inverse_func is None):
            self._check_inverse_transform(X)
+       self._check_feature_names(X, reset=True)
        return self
```

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

I've considered at least three alternatives:

1. Let the user incorporate the `._check_feature_names(...)` method themselves
2. Add a `.setter` method to the `feature_names_in_` property
3. Iterate over the `transformers` in the `transformer_list` and get the `feature_names_in_` from each

### Additional context

This is essentially the same as calling `.columns` on the input data if it has a `.columns` attribute (i.e. `pandas.DataFrame`). However, it would be helpful in examining individual steps if this `FeatureUnion` is buried deep in a series of transformations.

COMMENT:
> I am +1 on the proposal for always setting `feature_names_in_` in `FeatureUnion`. Do you want to open a PR for this change?

@thomasjpfan -- ~Yes. Do you have a link to a how-to for submitting a PR correctly?~ Never mind I found [it](https://github.com/scikit-learn/scikit-learn/blob/0e4e418eb2d34001724923b83111d5bb92edb4d1/CONTRIBUTING.md)!

Labels: New Feature, module:pipeline
add `feature_names_in_` attribute to `FeatureUnion`

### Describe the workflow you want to enable

The docs for `feature_names_in_` in the `sklearn.pipeline.Pipeline` say:

> feature_names_in_ : ndarray of shape (`n_features_in_`,)
        Names of features seen during :term:`fit`. Only defined if the
        underlying estimator exposes such an attribute when fit.

Several pipeline-friendly classes already have this attribute, e.g. `FunctionTransformer`, `LinearRegression`, `PCA`. It would be helpful if `FeatureUnion` also had this attribute.

### Describe your proposed solution

My proposed solution is to collect and store the `feature_names_in_` during fitting using the [`._check_feature_names(...)`](https://github.com/scikit-learn/scikit-learn/blob/36958fb240fbe435673a9e3c52e769f01f36bec0/sklearn/base.py#L405) method

```diff
    def fit(self, X, y=None):
        """Fit transformer by checking X.
        If ``validate`` is ``True``, ``X`` will be checked.
        Parameters
        ----------
        X : array-like, shape (n_samples, n_features)
            Input array.
        y : Ignored
            Not used, present here for API consistency by convention.
        Returns
        -------
        self : object
            FunctionTransformer class instance.
        """
        X = self._check_input(X, reset=True)
        if self.check_inverse and not (self.func is None or self.inverse_func is None):
            self._check_inverse_transform(X)
+       self._check_feature_names(X, reset=True)
        return self
```

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

I've considered at least three alternatives:

1. Let the user incorporate the `._check_feature_names(...)` method themselves
2. Add a `.setter` method to the `feature_names_in_` property
3. Iterate over the `transformers` in the `transformer_list` and get the `feature_names_in_` from each

### Additional context

This is essentially the same as calling `.columns` on the input data if it has a `.columns` attribute (i.e. `pandas.DataFrame`). However, it would be helpful in examining individual steps if this `FeatureUnion` is buried deep in a series of transformations.

COMMENT:
Our contribution guide has details on how to submit a PR: https://scikit-learn.org/dev/developers/contributing.html#contributing-code

Labels: New Feature, module:pipeline
add `feature_names_in_` attribute to `FeatureUnion`

### Describe the workflow you want to enable

The docs for `feature_names_in_` in the `sklearn.pipeline.Pipeline` say:

> feature_names_in_ : ndarray of shape (`n_features_in_`,)
        Names of features seen during :term:`fit`. Only defined if the
        underlying estimator exposes such an attribute when fit.

Several pipeline-friendly classes already have this attribute, e.g. `FunctionTransformer`, `LinearRegression`, `PCA`. It would be helpful if `FeatureUnion` also had this attribute.

### Describe your proposed solution

My proposed solution is to collect and store the `feature_names_in_` during fitting using the [`._check_feature_names(...)`](https://github.com/scikit-learn/scikit-learn/blob/36958fb240fbe435673a9e3c52e769f01f36bec0/sklearn/base.py#L405) method

```diff
    def fit(self, X, y=None):
        """Fit transformer by checking X.
        If ``validate`` is ``True``, ``X`` will be checked.
        Parameters
        ----------
        X : array-like, shape (n_samples, n_features)
            Input array.
        y : Ignored
            Not used, present here for API consistency by convention.
        Returns
        -------
        self : object
            FunctionTransformer class instance.
        """
        X = self._check_input(X, reset=True)
        if self.check_inverse and not (self.func is None or self.inverse_func is None):
            self._check_inverse_transform(X)
+       self._check_feature_names(X, reset=True)
        return self
```

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

I've considered at least three alternatives:

1. Let the user incorporate the `._check_feature_names(...)` method themselves
2. Add a `.setter` method to the `feature_names_in_` property
3. Iterate over the `transformers` in the `transformer_list` and get the `feature_names_in_` from each

### Additional context

This is essentially the same as calling `.columns` on the input data if it has a `.columns` attribute (i.e. `pandas.DataFrame`). However, it would be helpful in examining individual steps if this `FeatureUnion` is buried deep in a series of transformations.

COMMENT:
Closing since merged in #25220

Labels: New Feature, module:pipeline