Talip7/scikit-learn-issues-multilabel huggingface dataset:
verbose_feature_names_out default value

### Describe the workflow you want to enable

So I obviously love the example in https://scikit-learn.org/dev/auto_examples/miscellaneous/plot_set_output.html#sphx-glr-auto-examples-miscellaneous-plot-set-output-py

But it's a bit of a bummer that the pipeline needs so many parameters.
I wonder if we can revisit the default for ``verbose_feature_names_out``. I think we had a lengthy discussion about it, which I remember as follows

- if we do False by default, pipelines might start to fail that haven't failed before
- if we do "auto" by default (only prefix if required to disambiguate), feature names might start changing unexpectedly in a magic way
- if we do True by default, the names might be awkwardly long unnecessarily

So doing "true" seems the best trade-off for production-grade use....

### Describe your proposed solution

maybe this is a good reason to re-consider adding an "interactive" or "unsafe" mode with interactivity-friendly defaults? 

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

_No response_

### Additional context

_No response_

COMMENT:
> I like having an interactive mode. To clarify, are you proposing a global configuration option for "interactive mode"? If so, what other defaults would fall under this mode?

Yes, a global config. I'm not sure what else. Maybe some of the OHE options about handle_unknown? use all cores is definitely an interesting idea!

Maybe I'd go through the issue tracker and search for "too magic" and add all of those? ;)

Labels: Needs Decision, RFC
verbose_feature_names_out default value

### Describe the workflow you want to enable

So I obviously love the example in https://scikit-learn.org/dev/auto_examples/miscellaneous/plot_set_output.html#sphx-glr-auto-examples-miscellaneous-plot-set-output-py

But it's a bit of a bummer that the pipeline needs so many parameters.
I wonder if we can revisit the default for ``verbose_feature_names_out``. I think we had a lengthy discussion about it, which I remember as follows

- if we do False by default, pipelines might start to fail that haven't failed before
- if we do "auto" by default (only prefix if required to disambiguate), feature names might start changing unexpectedly in a magic way
- if we do True by default, the names might be awkwardly long unnecessarily

So doing "true" seems the best trade-off for production-grade use....

### Describe your proposed solution

maybe this is a good reason to re-consider adding an "interactive" or "unsafe" mode with interactivity-friendly defaults? 

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

_No response_

### Additional context

_No response_

COMMENT:
I agree that it is inconvenient to include `verbose_feature_names_out=False` every time I create a column transformer. Having a default that prevents the long names from being created would be convenient, but if that is unsafe, just having a global option to control the verbosity would go a long way so that we could set it once in the beginning an then forget about it; something like:

```py
set_config(transform_output="pandas", verbose_feature_names_out=False)   # or "interactive"
```

Even if there are other options to consider adding as global configurations, this one sounds like a helpful start on its own.

Labels: Needs Decision, RFC
AttributeError: 'MLPRegressor' object has no attribute '_best_coefs'

The following parameters were working fine with another dataset. When I switched to a new dataset, for some reason an `AttributeError` is occurring. Any ideas?

```python
model = MLPRegressor(hidden_layer_sizes=(10), activation='tanh', batch_size=1000,
  learning_rate_init=0.1, max_iter=5000, momentum=.9, solver='adam', early_stopping=True,
  random_state=1, verbose=1)
X = [[0.,0.,0.,0.2173913,0.,0.5,
  0.,0.46666667,0.76351351,0.41140777,0.55555556,0.03361345,
  0.09022556,0.78107607,0.13250518,1.,0.,0.,
  0.,0.,1.],
 [0.80769231,1.,0.,0.69565217,0.20942029,0.5,
  0.,0.13333333,0.,0.,0.88888889,0.95424837,
  0.96491228,0.83766234,0.97584541,0.,0.,0.,
  0.,0.,0.]] 
y = [1.0, 1.0]
model.fit(X, y)
```

Output:
```
...
Iteration 4997, loss = 0.00001391
Validation score: nan
Iteration 4998, loss = 0.00002568
Validation score: nan
Iteration 4999, loss = 0.00001822
Validation score: nan
Iteration 5000, loss = 0.00001470
Validation score: nan

AttributeError: 'MLPRegressor' object has no attribute '_best_coefs'
```

The error occurs here:
https://github.com/scikit-learn/scikit-learn/blob/7c2a58d51f4528827e9bfe9c43d06c5c1716bfb8/sklearn/neural_network/_multilayer_perceptron.py#L687

The error also seems to completely disappear when there are more than around 10-25 training examples.

COMMENT:
You have 2 samples and request `early_stopping`. From the verbose, it seems that the validation score is always `nan` probably because you are using 0 or 1 sample (10% of 2 samples). Since the coefficients are stored only if the score is decreasing, it actually never happens and thus `_best_coefs` is never set.

This is really a corner case and we choose to detect it much earlier even before to start trying to optimize the problem because we don't have enough samples in the validation set.

Labels: Bug, module:neural_network
AttributeError: 'MLPRegressor' object has no attribute '_best_coefs'

The following parameters were working fine with another dataset. When I switched to a new dataset, for some reason an `AttributeError` is occurring. Any ideas?

```python
model = MLPRegressor(hidden_layer_sizes=(10), activation='tanh', batch_size=1000,
  learning_rate_init=0.1, max_iter=5000, momentum=.9, solver='adam', early_stopping=True,
  random_state=1, verbose=1)
X = [[0.,0.,0.,0.2173913,0.,0.5,
  0.,0.46666667,0.76351351,0.41140777,0.55555556,0.03361345,
  0.09022556,0.78107607,0.13250518,1.,0.,0.,
  0.,0.,1.],
 [0.80769231,1.,0.,0.69565217,0.20942029,0.5,
  0.,0.13333333,0.,0.,0.88888889,0.95424837,
  0.96491228,0.83766234,0.97584541,0.,0.,0.,
  0.,0.,0.]] 
y = [1.0, 1.0]
model.fit(X, y)
```

Output:
```
...
Iteration 4997, loss = 0.00001391
Validation score: nan
Iteration 4998, loss = 0.00002568
Validation score: nan
Iteration 4999, loss = 0.00001822
Validation score: nan
Iteration 5000, loss = 0.00001470
Validation score: nan

AttributeError: 'MLPRegressor' object has no attribute '_best_coefs'
```

The error occurs here:
https://github.com/scikit-learn/scikit-learn/blob/7c2a58d51f4528827e9bfe9c43d06c5c1716bfb8/sklearn/neural_network/_multilayer_perceptron.py#L687

The error also seems to completely disappear when there are more than around 10-25 training examples.

COMMENT:
> The error also seems to completely disappear when there are more than around 10-25 training examples.

Be aware that you should not do any machine learning with so few samples.

Labels: Bug, module:neural_network
AttributeError: 'MLPRegressor' object has no attribute '_best_coefs'

The following parameters were working fine with another dataset. When I switched to a new dataset, for some reason an `AttributeError` is occurring. Any ideas?

```python
model = MLPRegressor(hidden_layer_sizes=(10), activation='tanh', batch_size=1000,
  learning_rate_init=0.1, max_iter=5000, momentum=.9, solver='adam', early_stopping=True,
  random_state=1, verbose=1)
X = [[0.,0.,0.,0.2173913,0.,0.5,
  0.,0.46666667,0.76351351,0.41140777,0.55555556,0.03361345,
  0.09022556,0.78107607,0.13250518,1.,0.,0.,
  0.,0.,1.],
 [0.80769231,1.,0.,0.69565217,0.20942029,0.5,
  0.,0.13333333,0.,0.,0.88888889,0.95424837,
  0.96491228,0.83766234,0.97584541,0.,0.,0.,
  0.,0.,0.]] 
y = [1.0, 1.0]
model.fit(X, y)
```

Output:
```
...
Iteration 4997, loss = 0.00001391
Validation score: nan
Iteration 4998, loss = 0.00002568
Validation score: nan
Iteration 4999, loss = 0.00001822
Validation score: nan
Iteration 5000, loss = 0.00001470
Validation score: nan

AttributeError: 'MLPRegressor' object has no attribute '_best_coefs'
```

The error occurs here:
https://github.com/scikit-learn/scikit-learn/blob/7c2a58d51f4528827e9bfe9c43d06c5c1716bfb8/sklearn/neural_network/_multilayer_perceptron.py#L687

The error also seems to completely disappear when there are more than around 10-25 training examples.

COMMENT:
> You have 2 samples and request early_stopping. From the verbose, it seems that the validation score is always nan probably because you are using 0 or 1 sample (10% of 2 samples). Since the coefficients are stored only if the score is decreasing, it actually never happens and thus _best_coefs is never set.

The example provided is 2 samples but it's happening with up to 10 samples.

Labels: Bug, module:neural_network
AttributeError: 'MLPRegressor' object has no attribute '_best_coefs'

The following parameters were working fine with another dataset. When I switched to a new dataset, for some reason an `AttributeError` is occurring. Any ideas?

```python
model = MLPRegressor(hidden_layer_sizes=(10), activation='tanh', batch_size=1000,
  learning_rate_init=0.1, max_iter=5000, momentum=.9, solver='adam', early_stopping=True,
  random_state=1, verbose=1)
X = [[0.,0.,0.,0.2173913,0.,0.5,
  0.,0.46666667,0.76351351,0.41140777,0.55555556,0.03361345,
  0.09022556,0.78107607,0.13250518,1.,0.,0.,
  0.,0.,1.],
 [0.80769231,1.,0.,0.69565217,0.20942029,0.5,
  0.,0.13333333,0.,0.,0.88888889,0.95424837,
  0.96491228,0.83766234,0.97584541,0.,0.,0.,
  0.,0.,0.]] 
y = [1.0, 1.0]
model.fit(X, y)
```

Output:
```
...
Iteration 4997, loss = 0.00001391
Validation score: nan
Iteration 4998, loss = 0.00002568
Validation score: nan
Iteration 4999, loss = 0.00001822
Validation score: nan
Iteration 5000, loss = 0.00001470
Validation score: nan

AttributeError: 'MLPRegressor' object has no attribute '_best_coefs'
```

The error occurs here:
https://github.com/scikit-learn/scikit-learn/blob/7c2a58d51f4528827e9bfe9c43d06c5c1716bfb8/sklearn/neural_network/_multilayer_perceptron.py#L687

The error also seems to completely disappear when there are more than around 10-25 training examples.

COMMENT:
Yes you need at least 2 samples to compute the R2 scores. By default, you take 10% validation. so above 10 samples, you get the required 2 samples (with the rounding).

Labels: Bug, module:neural_network
AttributeError: 'MLPRegressor' object has no attribute '_best_coefs'

The following parameters were working fine with another dataset. When I switched to a new dataset, for some reason an `AttributeError` is occurring. Any ideas?

```python
model = MLPRegressor(hidden_layer_sizes=(10), activation='tanh', batch_size=1000,
  learning_rate_init=0.1, max_iter=5000, momentum=.9, solver='adam', early_stopping=True,
  random_state=1, verbose=1)
X = [[0.,0.,0.,0.2173913,0.,0.5,
  0.,0.46666667,0.76351351,0.41140777,0.55555556,0.03361345,
  0.09022556,0.78107607,0.13250518,1.,0.,0.,
  0.,0.,1.],
 [0.80769231,1.,0.,0.69565217,0.20942029,0.5,
  0.,0.13333333,0.,0.,0.88888889,0.95424837,
  0.96491228,0.83766234,0.97584541,0.,0.,0.,
  0.,0.,0.]] 
y = [1.0, 1.0]
model.fit(X, y)
```

Output:
```
...
Iteration 4997, loss = 0.00001391
Validation score: nan
Iteration 4998, loss = 0.00002568
Validation score: nan
Iteration 4999, loss = 0.00001822
Validation score: nan
Iteration 5000, loss = 0.00001470
Validation score: nan

AttributeError: 'MLPRegressor' object has no attribute '_best_coefs'
```

The error occurs here:
https://github.com/scikit-learn/scikit-learn/blob/7c2a58d51f4528827e9bfe9c43d06c5c1716bfb8/sklearn/neural_network/_multilayer_perceptron.py#L687

The error also seems to completely disappear when there are more than around 10-25 training examples.

COMMENT:
> Yes you need at least 2 samples to compute the R2 scores. By default, you take 10% validation. so above 10 samples, you get the required 2 samples (with the rounding).

Aha got it

Labels: Bug, module:neural_network
AttributeError: 'MLPRegressor' object has no attribute '_best_coefs'

The following parameters were working fine with another dataset. When I switched to a new dataset, for some reason an `AttributeError` is occurring. Any ideas?

```python
model = MLPRegressor(hidden_layer_sizes=(10), activation='tanh', batch_size=1000,
  learning_rate_init=0.1, max_iter=5000, momentum=.9, solver='adam', early_stopping=True,
  random_state=1, verbose=1)
X = [[0.,0.,0.,0.2173913,0.,0.5,
  0.,0.46666667,0.76351351,0.41140777,0.55555556,0.03361345,
  0.09022556,0.78107607,0.13250518,1.,0.,0.,
  0.,0.,1.],
 [0.80769231,1.,0.,0.69565217,0.20942029,0.5,
  0.,0.13333333,0.,0.,0.88888889,0.95424837,
  0.96491228,0.83766234,0.97584541,0.,0.,0.,
  0.,0.,0.]] 
y = [1.0, 1.0]
model.fit(X, y)
```

Output:
```
...
Iteration 4997, loss = 0.00001391
Validation score: nan
Iteration 4998, loss = 0.00002568
Validation score: nan
Iteration 4999, loss = 0.00001822
Validation score: nan
Iteration 5000, loss = 0.00001470
Validation score: nan

AttributeError: 'MLPRegressor' object has no attribute '_best_coefs'
```

The error occurs here:
https://github.com/scikit-learn/scikit-learn/blob/7c2a58d51f4528827e9bfe9c43d06c5c1716bfb8/sklearn/neural_network/_multilayer_perceptron.py#L687

The error also seems to completely disappear when there are more than around 10-25 training examples.

COMMENT:
> This is really a corner case and we choose to detect it much earlier even before to start trying to optimize the problem because we don't have enough samples in the validation set.

Does the earlier check actually get made? If yes, why did it not catch this case? Or was your comment a "we should detect it much earlier" -> a PR would be helpful/welcome to implement this?

Labels: Bug, module:neural_network
AttributeError: 'MLPRegressor' object has no attribute '_best_coefs'

The following parameters were working fine with another dataset. When I switched to a new dataset, for some reason an `AttributeError` is occurring. Any ideas?

```python
model = MLPRegressor(hidden_layer_sizes=(10), activation='tanh', batch_size=1000,
  learning_rate_init=0.1, max_iter=5000, momentum=.9, solver='adam', early_stopping=True,
  random_state=1, verbose=1)
X = [[0.,0.,0.,0.2173913,0.,0.5,
  0.,0.46666667,0.76351351,0.41140777,0.55555556,0.03361345,
  0.09022556,0.78107607,0.13250518,1.,0.,0.,
  0.,0.,1.],
 [0.80769231,1.,0.,0.69565217,0.20942029,0.5,
  0.,0.13333333,0.,0.,0.88888889,0.95424837,
  0.96491228,0.83766234,0.97584541,0.,0.,0.,
  0.,0.,0.]] 
y = [1.0, 1.0]
model.fit(X, y)
```

Output:
```
...
Iteration 4997, loss = 0.00001391
Validation score: nan
Iteration 4998, loss = 0.00002568
Validation score: nan
Iteration 4999, loss = 0.00001822
Validation score: nan
Iteration 5000, loss = 0.00001470
Validation score: nan

AttributeError: 'MLPRegressor' object has no attribute '_best_coefs'
```

The error occurs here:
https://github.com/scikit-learn/scikit-learn/blob/7c2a58d51f4528827e9bfe9c43d06c5c1716bfb8/sklearn/neural_network/_multilayer_perceptron.py#L687

The error also seems to completely disappear when there are more than around 10-25 training examples.

COMMENT:
Sorry for the confusion.

I meant that we should create a PR to detect this case (i.e. not enough samples to compute the validation metric) and raise an error.

Labels: Bug, module:neural_network
AttributeError: 'MLPRegressor' object has no attribute '_best_coefs'

The following parameters were working fine with another dataset. When I switched to a new dataset, for some reason an `AttributeError` is occurring. Any ideas?

```python
model = MLPRegressor(hidden_layer_sizes=(10), activation='tanh', batch_size=1000,
  learning_rate_init=0.1, max_iter=5000, momentum=.9, solver='adam', early_stopping=True,
  random_state=1, verbose=1)
X = [[0.,0.,0.,0.2173913,0.,0.5,
  0.,0.46666667,0.76351351,0.41140777,0.55555556,0.03361345,
  0.09022556,0.78107607,0.13250518,1.,0.,0.,
  0.,0.,1.],
 [0.80769231,1.,0.,0.69565217,0.20942029,0.5,
  0.,0.13333333,0.,0.,0.88888889,0.95424837,
  0.96491228,0.83766234,0.97584541,0.,0.,0.,
  0.,0.,0.]] 
y = [1.0, 1.0]
model.fit(X, y)
```

Output:
```
...
Iteration 4997, loss = 0.00001391
Validation score: nan
Iteration 4998, loss = 0.00002568
Validation score: nan
Iteration 4999, loss = 0.00001822
Validation score: nan
Iteration 5000, loss = 0.00001470
Validation score: nan

AttributeError: 'MLPRegressor' object has no attribute '_best_coefs'
```

The error occurs here:
https://github.com/scikit-learn/scikit-learn/blob/7c2a58d51f4528827e9bfe9c43d06c5c1716bfb8/sklearn/neural_network/_multilayer_perceptron.py#L687

The error also seems to completely disappear when there are more than around 10-25 training examples.

COMMENT:
Hi @glemaitre ,
As nobody seemed to have taken it up, I tried to attempt to design a fix based on your recommendation. Would you like to have a look at it and suggest improvements? (See PR above.)
Thank you.

Labels: Bug, module:neural_network
AttributeError: 'MLPRegressor' object has no attribute '_best_coefs'

The following parameters were working fine with another dataset. When I switched to a new dataset, for some reason an `AttributeError` is occurring. Any ideas?

```python
model = MLPRegressor(hidden_layer_sizes=(10), activation='tanh', batch_size=1000,
  learning_rate_init=0.1, max_iter=5000, momentum=.9, solver='adam', early_stopping=True,
  random_state=1, verbose=1)
X = [[0.,0.,0.,0.2173913,0.,0.5,
  0.,0.46666667,0.76351351,0.41140777,0.55555556,0.03361345,
  0.09022556,0.78107607,0.13250518,1.,0.,0.,
  0.,0.,1.],
 [0.80769231,1.,0.,0.69565217,0.20942029,0.5,
  0.,0.13333333,0.,0.,0.88888889,0.95424837,
  0.96491228,0.83766234,0.97584541,0.,0.,0.,
  0.,0.,0.]] 
y = [1.0, 1.0]
model.fit(X, y)
```

Output:
```
...
Iteration 4997, loss = 0.00001391
Validation score: nan
Iteration 4998, loss = 0.00002568
Validation score: nan
Iteration 4999, loss = 0.00001822
Validation score: nan
Iteration 5000, loss = 0.00001470
Validation score: nan

AttributeError: 'MLPRegressor' object has no attribute '_best_coefs'
```

The error occurs here:
https://github.com/scikit-learn/scikit-learn/blob/7c2a58d51f4528827e9bfe9c43d06c5c1716bfb8/sklearn/neural_network/_multilayer_perceptron.py#L687

The error also seems to completely disappear when there are more than around 10-25 training examples.

COMMENT:
Hi @glemaitre,

I hope you're doing well. I came across this issue and wanted to check if someone is already working on it. If it's still open and no one is currently assigned, I’d happily take it up and work on resolving it.

Looking forward to your response.

Labels: Bug, module:neural_network
AttributeError: 'MLPRegressor' object has no attribute '_best_coefs'

The following parameters were working fine with another dataset. When I switched to a new dataset, for some reason an `AttributeError` is occurring. Any ideas?

```python
model = MLPRegressor(hidden_layer_sizes=(10), activation='tanh', batch_size=1000,
  learning_rate_init=0.1, max_iter=5000, momentum=.9, solver='adam', early_stopping=True,
  random_state=1, verbose=1)
X = [[0.,0.,0.,0.2173913,0.,0.5,
  0.,0.46666667,0.76351351,0.41140777,0.55555556,0.03361345,
  0.09022556,0.78107607,0.13250518,1.,0.,0.,
  0.,0.,1.],
 [0.80769231,1.,0.,0.69565217,0.20942029,0.5,
  0.,0.13333333,0.,0.,0.88888889,0.95424837,
  0.96491228,0.83766234,0.97584541,0.,0.,0.,
  0.,0.,0.]] 
y = [1.0, 1.0]
model.fit(X, y)
```

Output:
```
...
Iteration 4997, loss = 0.00001391
Validation score: nan
Iteration 4998, loss = 0.00002568
Validation score: nan
Iteration 4999, loss = 0.00001822
Validation score: nan
Iteration 5000, loss = 0.00001470
Validation score: nan

AttributeError: 'MLPRegressor' object has no attribute '_best_coefs'
```

The error occurs here:
https://github.com/scikit-learn/scikit-learn/blob/7c2a58d51f4528827e9bfe9c43d06c5c1716bfb8/sklearn/neural_network/_multilayer_perceptron.py#L687

The error also seems to completely disappear when there are more than around 10-25 training examples.

COMMENT:
It looks like https://github.com/scikit-learn/scikit-learn/pull/24788 has been open. Before to open a new PR, I'll like to have a look at this open PR because it seems that we did not provide feedback.

Labels: Bug, module:neural_network
KNN for dim > 2

### Describe the workflow you want to enable

Applying Knn to data with dim > 2:

File "/usr/local/lib/python3.7/dist-packages/sklearn/neighbors/_graph.py", line 120, in kneighbors_graph
    ).fit(X)
  File "/usr/local/lib/python3.7/dist-packages/sklearn/neighbors/_unsupervised.py", line 166, in fit
    return self._fit(X)
  File "/usr/local/lib/python3.7/dist-packages/sklearn/neighbors/_base.py", line 435, in _fit
    X = self._validate_data(X, accept_sparse="csr")
  File "/usr/local/lib/python3.7/dist-packages/sklearn/base.py", line 566, in _validate_data
    X = check_array(X, **check_params)
  File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/validation.py", line 796, in check_array
    % (array.ndim, estimator_name)
ValueError: Found array with dim 3. Estimator expected <= 2.

### Describe your proposed solution

Data ----> Dim. Reduction ---------> Knn

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

_No response_

### Additional context

_No response_

COMMENT:
The scikit-learn estimator only accepts a 2D matrix for `X` with a shape of `(n_samples, n_features)`. This will not change in a near future.

Labels: New Feature, Needs Triage