Talip7/scikit-learn-issues-multilabel huggingface dataset:
MLPClassifier: Cannot turn off convergence warning without side effects

### Describe the bug

As [described](https://github.com/scikit-learn/scikit-learn/discussions/27062) by @qrdlgit, it can have sense to use MLPClassifier with small `max_iter` that are always reached. In this case, I get
```
ConvergenceWarning: lbfgs failed to converge (status=1): 
STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.
```
The bug is that I have no side-effect free way to disable this convergence warning except for the case of `n_jobs=1`, as described [here](https://github.com/scikit-learn/scikit-learn/discussions/27062#discussioncomment-7145084).


### Steps/Code to Reproduce

Remove the `ignore_warnings` here: https://github.com/scikit-learn/scikit-learn/blob/de29f3f22db6e017aef9dc77935d8ef43d2d7b44/sklearn/neural_network/tests/test_mlp.py#L70

### Expected Results

There should be a way to tell the MLPClassifier not to show this convergence warning.

### Actual Results

I cannot suppress the warnings without changing environment variables.

### Versions

<details>
```shell
System:
    python: 3.11.1 (tags/v3.11.1:a7a450f, Dec  6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)]
executable: [***]\WPy64-31110\python-3.11.1.amd64\python.exe
   machine: Windows-10-10.0.19045-SP0

Python dependencies:
      sklearn: 1.2.2
          pip: 22.3.1
   setuptools: 65.5.0
        numpy: 1.24.3
        scipy: 1.10.1
       Cython: None
       pandas: 2.0.1
   matplotlib: 3.7.1
       joblib: 1.2.0
threadpoolctl: 3.1.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: [***]\WPy64-31110\python-3.11.1.amd64\Lib\site-packages\numpy\.libs\libopenblas64__v0.3.21-gcc_10_3_0.dll
        version: 0.3.21
threading_layer: pthreads
   architecture: Haswell
    num_threads: 8

       user_api: openmp
   internal_api: openmp
         prefix: vcomp
       filepath: [***]\WPy64-31110\python-3.11.1.amd64\Lib\site-packages\sklearn\.libs\vcomp140.dll
        version: None
    num_threads: 8

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: [***]\WPy64-31110\python-3.11.1.amd64\Lib\site-packages\scipy.libs\libopenblas-802f9ed1179cb9c9b03d67ff79f48187.dll
        version: 0.3.18
threading_layer: pthreads
   architecture: Haswell
    num_threads: 8
```
</details>

COMMENT:
@hakunamatata1997, for me it is. My `GridSearchCV` fills my console with a huge number of those warnings, such that it becomes difficult to spot actual error messages among them - especially because many of the warnings are only flushed *after* the script has stopped with an error.

Labels: Bug, Needs Triage
MLPClassifier: Cannot turn off convergence warning without side effects

### Describe the bug

As [described](https://github.com/scikit-learn/scikit-learn/discussions/27062) by @qrdlgit, it can have sense to use MLPClassifier with small `max_iter` that are always reached. In this case, I get
```
ConvergenceWarning: lbfgs failed to converge (status=1): 
STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.
```
The bug is that I have no side-effect free way to disable this convergence warning except for the case of `n_jobs=1`, as described [here](https://github.com/scikit-learn/scikit-learn/discussions/27062#discussioncomment-7145084).


### Steps/Code to Reproduce

Remove the `ignore_warnings` here: https://github.com/scikit-learn/scikit-learn/blob/de29f3f22db6e017aef9dc77935d8ef43d2d7b44/sklearn/neural_network/tests/test_mlp.py#L70

### Expected Results

There should be a way to tell the MLPClassifier not to show this convergence warning.

### Actual Results

I cannot suppress the warnings without changing environment variables.

### Versions

<details>
```shell
System:
    python: 3.11.1 (tags/v3.11.1:a7a450f, Dec  6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)]
executable: [***]\WPy64-31110\python-3.11.1.amd64\python.exe
   machine: Windows-10-10.0.19045-SP0

Python dependencies:
      sklearn: 1.2.2
          pip: 22.3.1
   setuptools: 65.5.0
        numpy: 1.24.3
        scipy: 1.10.1
       Cython: None
       pandas: 2.0.1
   matplotlib: 3.7.1
       joblib: 1.2.0
threadpoolctl: 3.1.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: [***]\WPy64-31110\python-3.11.1.amd64\Lib\site-packages\numpy\.libs\libopenblas64__v0.3.21-gcc_10_3_0.dll
        version: 0.3.21
threading_layer: pthreads
   architecture: Haswell
    num_threads: 8

       user_api: openmp
   internal_api: openmp
         prefix: vcomp
       filepath: [***]\WPy64-31110\python-3.11.1.amd64\Lib\site-packages\sklearn\.libs\vcomp140.dll
        version: None
    num_threads: 8

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: [***]\WPy64-31110\python-3.11.1.amd64\Lib\site-packages\scipy.libs\libopenblas-802f9ed1179cb9c9b03d67ff79f48187.dll
        version: 0.3.18
threading_layer: pthreads
   architecture: Haswell
    num_threads: 8
```
</details>

COMMENT:
Does using the [`warnings.catch_warnings` context manager](https://docs.python.org/3/library/warnings.html#warnings.catch_warnings) around the part of your code where you want to silence warnings or globally filtering `ConvergenceWarning`s for your application work for you?

This seems like what you are looking for, a way to disable the warning for cases where you know what you are doing/that there will be a warning that is harmless.

Labels: Bug, Needs Triage
MLPClassifier: Cannot turn off convergence warning without side effects

### Describe the bug

As [described](https://github.com/scikit-learn/scikit-learn/discussions/27062) by @qrdlgit, it can have sense to use MLPClassifier with small `max_iter` that are always reached. In this case, I get
```
ConvergenceWarning: lbfgs failed to converge (status=1): 
STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.
```
The bug is that I have no side-effect free way to disable this convergence warning except for the case of `n_jobs=1`, as described [here](https://github.com/scikit-learn/scikit-learn/discussions/27062#discussioncomment-7145084).


### Steps/Code to Reproduce

Remove the `ignore_warnings` here: https://github.com/scikit-learn/scikit-learn/blob/de29f3f22db6e017aef9dc77935d8ef43d2d7b44/sklearn/neural_network/tests/test_mlp.py#L70

### Expected Results

There should be a way to tell the MLPClassifier not to show this convergence warning.

### Actual Results

I cannot suppress the warnings without changing environment variables.

### Versions

<details>
```shell
System:
    python: 3.11.1 (tags/v3.11.1:a7a450f, Dec  6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)]
executable: [***]\WPy64-31110\python-3.11.1.amd64\python.exe
   machine: Windows-10-10.0.19045-SP0

Python dependencies:
      sklearn: 1.2.2
          pip: 22.3.1
   setuptools: 65.5.0
        numpy: 1.24.3
        scipy: 1.10.1
       Cython: None
       pandas: 2.0.1
   matplotlib: 3.7.1
       joblib: 1.2.0
threadpoolctl: 3.1.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: [***]\WPy64-31110\python-3.11.1.amd64\Lib\site-packages\numpy\.libs\libopenblas64__v0.3.21-gcc_10_3_0.dll
        version: 0.3.21
threading_layer: pthreads
   architecture: Haswell
    num_threads: 8

       user_api: openmp
   internal_api: openmp
         prefix: vcomp
       filepath: [***]\WPy64-31110\python-3.11.1.amd64\Lib\site-packages\sklearn\.libs\vcomp140.dll
        version: None
    num_threads: 8

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: [***]\WPy64-31110\python-3.11.1.amd64\Lib\site-packages\scipy.libs\libopenblas-802f9ed1179cb9c9b03d67ff79f48187.dll
        version: 0.3.18
threading_layer: pthreads
   architecture: Haswell
    num_threads: 8
```
</details>

COMMENT:
I have got
```
gs = GridSearchCV(estimator=estimator, param_grid=param_grid, scoring=scoring, cv=n_folds, n_jobs=n_jobs)
with warnings.catch_warnings():
    warnings.filterwarnings("ignore", category=ConvergenceWarning)
    gs.fit(X_fit, y_fit)
```
However,the `warnings.catch_warnings()` context manager is [not thread safe](https://github.com/python/cpython/issues/50896#issuecomment-1093476635). So this filter only works for `n_jobs=1`.

Labels: Bug, Needs Triage
MLPClassifier: Cannot turn off convergence warning without side effects

### Describe the bug

As [described](https://github.com/scikit-learn/scikit-learn/discussions/27062) by @qrdlgit, it can have sense to use MLPClassifier with small `max_iter` that are always reached. In this case, I get
```
ConvergenceWarning: lbfgs failed to converge (status=1): 
STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.
```
The bug is that I have no side-effect free way to disable this convergence warning except for the case of `n_jobs=1`, as described [here](https://github.com/scikit-learn/scikit-learn/discussions/27062#discussioncomment-7145084).


### Steps/Code to Reproduce

Remove the `ignore_warnings` here: https://github.com/scikit-learn/scikit-learn/blob/de29f3f22db6e017aef9dc77935d8ef43d2d7b44/sklearn/neural_network/tests/test_mlp.py#L70

### Expected Results

There should be a way to tell the MLPClassifier not to show this convergence warning.

### Actual Results

I cannot suppress the warnings without changing environment variables.

### Versions

<details>
```shell
System:
    python: 3.11.1 (tags/v3.11.1:a7a450f, Dec  6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)]
executable: [***]\WPy64-31110\python-3.11.1.amd64\python.exe
   machine: Windows-10-10.0.19045-SP0

Python dependencies:
      sklearn: 1.2.2
          pip: 22.3.1
   setuptools: 65.5.0
        numpy: 1.24.3
        scipy: 1.10.1
       Cython: None
       pandas: 2.0.1
   matplotlib: 3.7.1
       joblib: 1.2.0
threadpoolctl: 3.1.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: [***]\WPy64-31110\python-3.11.1.amd64\Lib\site-packages\numpy\.libs\libopenblas64__v0.3.21-gcc_10_3_0.dll
        version: 0.3.21
threading_layer: pthreads
   architecture: Haswell
    num_threads: 8

       user_api: openmp
   internal_api: openmp
         prefix: vcomp
       filepath: [***]\WPy64-31110\python-3.11.1.amd64\Lib\site-packages\sklearn\.libs\vcomp140.dll
        version: None
    num_threads: 8

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: [***]\WPy64-31110\python-3.11.1.amd64\Lib\site-packages\scipy.libs\libopenblas-802f9ed1179cb9c9b03d67ff79f48187.dll
        version: 0.3.18
threading_layer: pthreads
   architecture: Haswell
    num_threads: 8
```
</details>

COMMENT:
Could you post a minimal reproducer?

The thread safety is about when multiple threads enter/exit the `catch_warnings` context manager, not when multiple threads run inside it.

For me the following does not print a warning:
```python
import warnings

# comment out the next line to see the warning
warnings.simplefilter('ignore', category=ConvergenceWarning)
MLPClassifier(hidden_layer_sizes=10, max_iter=3, random_state=1).fit(X, y)
```

Labels: Bug, Needs Triage
MLPClassifier: Cannot turn off convergence warning without side effects

### Describe the bug

As [described](https://github.com/scikit-learn/scikit-learn/discussions/27062) by @qrdlgit, it can have sense to use MLPClassifier with small `max_iter` that are always reached. In this case, I get
```
ConvergenceWarning: lbfgs failed to converge (status=1): 
STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.
```
The bug is that I have no side-effect free way to disable this convergence warning except for the case of `n_jobs=1`, as described [here](https://github.com/scikit-learn/scikit-learn/discussions/27062#discussioncomment-7145084).


### Steps/Code to Reproduce

Remove the `ignore_warnings` here: https://github.com/scikit-learn/scikit-learn/blob/de29f3f22db6e017aef9dc77935d8ef43d2d7b44/sklearn/neural_network/tests/test_mlp.py#L70

### Expected Results

There should be a way to tell the MLPClassifier not to show this convergence warning.

### Actual Results

I cannot suppress the warnings without changing environment variables.

### Versions

<details>
```shell
System:
    python: 3.11.1 (tags/v3.11.1:a7a450f, Dec  6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)]
executable: [***]\WPy64-31110\python-3.11.1.amd64\python.exe
   machine: Windows-10-10.0.19045-SP0

Python dependencies:
      sklearn: 1.2.2
          pip: 22.3.1
   setuptools: 65.5.0
        numpy: 1.24.3
        scipy: 1.10.1
       Cython: None
       pandas: 2.0.1
   matplotlib: 3.7.1
       joblib: 1.2.0
threadpoolctl: 3.1.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: [***]\WPy64-31110\python-3.11.1.amd64\Lib\site-packages\numpy\.libs\libopenblas64__v0.3.21-gcc_10_3_0.dll
        version: 0.3.21
threading_layer: pthreads
   architecture: Haswell
    num_threads: 8

       user_api: openmp
   internal_api: openmp
         prefix: vcomp
       filepath: [***]\WPy64-31110\python-3.11.1.amd64\Lib\site-packages\sklearn\.libs\vcomp140.dll
        version: None
    num_threads: 8

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: [***]\WPy64-31110\python-3.11.1.amd64\Lib\site-packages\scipy.libs\libopenblas-802f9ed1179cb9c9b03d67ff79f48187.dll
        version: 0.3.18
threading_layer: pthreads
   architecture: Haswell
    num_threads: 8
```
</details>

COMMENT:
@betatim 

But what if the MLPClassifier is in an ensemble classifier, and you want to ignore one convergence warning but not another?  Especially cases with 3rd party frameworks where you can only effect change on the params.

Running MLPs for max iters regardless of convergence is a **very** standard technique.  I get that most people just use torch here which is probably why you get few comments on this, but still, it'd be nice to have this in sklearn for those cases when testing and blending in an MLP would be of interest.

I'm a bit perplexed by the pushback here.  The issue seems rather clear.   Is this a tricky thing to address?

Labels: Bug, Needs Triage
MLPClassifier: Cannot turn off convergence warning without side effects

### Describe the bug

As [described](https://github.com/scikit-learn/scikit-learn/discussions/27062) by @qrdlgit, it can have sense to use MLPClassifier with small `max_iter` that are always reached. In this case, I get
```
ConvergenceWarning: lbfgs failed to converge (status=1): 
STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.
```
The bug is that I have no side-effect free way to disable this convergence warning except for the case of `n_jobs=1`, as described [here](https://github.com/scikit-learn/scikit-learn/discussions/27062#discussioncomment-7145084).


### Steps/Code to Reproduce

Remove the `ignore_warnings` here: https://github.com/scikit-learn/scikit-learn/blob/de29f3f22db6e017aef9dc77935d8ef43d2d7b44/sklearn/neural_network/tests/test_mlp.py#L70

### Expected Results

There should be a way to tell the MLPClassifier not to show this convergence warning.

### Actual Results

I cannot suppress the warnings without changing environment variables.

### Versions

<details>
```shell
System:
    python: 3.11.1 (tags/v3.11.1:a7a450f, Dec  6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)]
executable: [***]\WPy64-31110\python-3.11.1.amd64\python.exe
   machine: Windows-10-10.0.19045-SP0

Python dependencies:
      sklearn: 1.2.2
          pip: 22.3.1
   setuptools: 65.5.0
        numpy: 1.24.3
        scipy: 1.10.1
       Cython: None
       pandas: 2.0.1
   matplotlib: 3.7.1
       joblib: 1.2.0
threadpoolctl: 3.1.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: [***]\WPy64-31110\python-3.11.1.amd64\Lib\site-packages\numpy\.libs\libopenblas64__v0.3.21-gcc_10_3_0.dll
        version: 0.3.21
threading_layer: pthreads
   architecture: Haswell
    num_threads: 8

       user_api: openmp
   internal_api: openmp
         prefix: vcomp
       filepath: [***]\WPy64-31110\python-3.11.1.amd64\Lib\site-packages\sklearn\.libs\vcomp140.dll
        version: None
    num_threads: 8

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: [***]\WPy64-31110\python-3.11.1.amd64\Lib\site-packages\scipy.libs\libopenblas-802f9ed1179cb9c9b03d67ff79f48187.dll
        version: 0.3.18
threading_layer: pthreads
   architecture: Haswell
    num_threads: 8
```
</details>

COMMENT:
To me there's no blanket decision for warnings when it comes to "should the user be able to easily suppress them or not". In this particular case, i.e. ConvergenceWarning, I agree that the user can suppress it if they really want, as @betatim suggests, and otherwise I think these warnings should in almost all cases be seen.

So I'm seconding @betatim and closing this issue as won't fix.

Labels: Bug, Needs Triage
MLPClassifier: Cannot turn off convergence warning without side effects

### Describe the bug

As [described](https://github.com/scikit-learn/scikit-learn/discussions/27062) by @qrdlgit, it can have sense to use MLPClassifier with small `max_iter` that are always reached. In this case, I get
```
ConvergenceWarning: lbfgs failed to converge (status=1): 
STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.
```
The bug is that I have no side-effect free way to disable this convergence warning except for the case of `n_jobs=1`, as described [here](https://github.com/scikit-learn/scikit-learn/discussions/27062#discussioncomment-7145084).


### Steps/Code to Reproduce

Remove the `ignore_warnings` here: https://github.com/scikit-learn/scikit-learn/blob/de29f3f22db6e017aef9dc77935d8ef43d2d7b44/sklearn/neural_network/tests/test_mlp.py#L70

### Expected Results

There should be a way to tell the MLPClassifier not to show this convergence warning.

### Actual Results

I cannot suppress the warnings without changing environment variables.

### Versions

<details>
```shell
System:
    python: 3.11.1 (tags/v3.11.1:a7a450f, Dec  6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)]
executable: [***]\WPy64-31110\python-3.11.1.amd64\python.exe
   machine: Windows-10-10.0.19045-SP0

Python dependencies:
      sklearn: 1.2.2
          pip: 22.3.1
   setuptools: 65.5.0
        numpy: 1.24.3
        scipy: 1.10.1
       Cython: None
       pandas: 2.0.1
   matplotlib: 3.7.1
       joblib: 1.2.0
threadpoolctl: 3.1.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: [***]\WPy64-31110\python-3.11.1.amd64\Lib\site-packages\numpy\.libs\libopenblas64__v0.3.21-gcc_10_3_0.dll
        version: 0.3.21
threading_layer: pthreads
   architecture: Haswell
    num_threads: 8

       user_api: openmp
   internal_api: openmp
         prefix: vcomp
       filepath: [***]\WPy64-31110\python-3.11.1.amd64\Lib\site-packages\sklearn\.libs\vcomp140.dll
        version: None
    num_threads: 8

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: [***]\WPy64-31110\python-3.11.1.amd64\Lib\site-packages\scipy.libs\libopenblas-802f9ed1179cb9c9b03d67ff79f48187.dll
        version: 0.3.18
threading_layer: pthreads
   architecture: Haswell
    num_threads: 8
```
</details>

COMMENT:
The problem I have is specific to MLPClassifier.  I find the convergence warning anti pattern for mlps, and respecting the warning has frequently led to overfitting.  I think it's doing a disservice to an otherwise useful learner.

Labels: Bug, Needs Triage
MLPClassifier: Cannot turn off convergence warning without side effects

### Describe the bug

As [described](https://github.com/scikit-learn/scikit-learn/discussions/27062) by @qrdlgit, it can have sense to use MLPClassifier with small `max_iter` that are always reached. In this case, I get
```
ConvergenceWarning: lbfgs failed to converge (status=1): 
STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.
```
The bug is that I have no side-effect free way to disable this convergence warning except for the case of `n_jobs=1`, as described [here](https://github.com/scikit-learn/scikit-learn/discussions/27062#discussioncomment-7145084).


### Steps/Code to Reproduce

Remove the `ignore_warnings` here: https://github.com/scikit-learn/scikit-learn/blob/de29f3f22db6e017aef9dc77935d8ef43d2d7b44/sklearn/neural_network/tests/test_mlp.py#L70

### Expected Results

There should be a way to tell the MLPClassifier not to show this convergence warning.

### Actual Results

I cannot suppress the warnings without changing environment variables.

### Versions

<details>
```shell
System:
    python: 3.11.1 (tags/v3.11.1:a7a450f, Dec  6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)]
executable: [***]\WPy64-31110\python-3.11.1.amd64\python.exe
   machine: Windows-10-10.0.19045-SP0

Python dependencies:
      sklearn: 1.2.2
          pip: 22.3.1
   setuptools: 65.5.0
        numpy: 1.24.3
        scipy: 1.10.1
       Cython: None
       pandas: 2.0.1
   matplotlib: 3.7.1
       joblib: 1.2.0
threadpoolctl: 3.1.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: [***]\WPy64-31110\python-3.11.1.amd64\Lib\site-packages\numpy\.libs\libopenblas64__v0.3.21-gcc_10_3_0.dll
        version: 0.3.21
threading_layer: pthreads
   architecture: Haswell
    num_threads: 8

       user_api: openmp
   internal_api: openmp
         prefix: vcomp
       filepath: [***]\WPy64-31110\python-3.11.1.amd64\Lib\site-packages\sklearn\.libs\vcomp140.dll
        version: None
    num_threads: 8

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: [***]\WPy64-31110\python-3.11.1.amd64\Lib\site-packages\scipy.libs\libopenblas-802f9ed1179cb9c9b03d67ff79f48187.dll
        version: 0.3.18
threading_layer: pthreads
   architecture: Haswell
    num_threads: 8
```
</details>

COMMENT:
Specifically for MLPs, it's here mostly for educational purposes, for any serious deployment, people should use other frameworks, and you can use skorch or scikeras to have scikit-learn compatible NN models.

Labels: Bug, Needs Triage