Talip7/scikit-learn-issues-multilabel huggingface dataset:
`MinMaxScalar.fit_transform()` Returns Zero When All Elements Are Same

### Describe the bug

When using MinMaxScaler.fit_transform() from scikit-learn, if all elements in a column of data are the same, the scaler transforms these elements to zeros. This behavior might not be intuitive or desired in some cases, as users might expect a different treatment for constant columns (e.g., transforming to ones or maintaining the constant value). If this behavior is expected, feel free to close this issue!

### Steps/Code to Reproduce

```python
import pandas as pd
from sklearn.preprocessing import MinMaxScaler

# Sample DataFrame with constant columns
df = pd.DataFrame({
    'A': [5, 5, 5],  # Constant column
    'B': [1, 2, 3]   # Varying column
})

# Apply MinMaxScaler
scaler = MinMaxScaler()
scaled_df = pd.DataFrame(scaler.fit_transform(df), columns=df.columns)

print(scaled_df)
```

### Expected Results

It might be more intuitive if constant columns are scaled to a non-zero constant value (e.g., all ones) or maintain their original value.

### Actual Results

The constant column ('A') is transformed to all zeros.
```shell
     A    B
0  0.0  0.0
1  0.0  0.5
2  0.0  1.0
```
### Versions

```shell
System:
    python: 3.9.17 (main, Jul  5 2023, 20:41:20)  [GCC 11.2.0]
executable: /home/guihuan/.conda/envs/py39/bin/python
   machine: Linux-5.15.0-86-generic-x86_64-with-glibc2.35

Python dependencies:
      sklearn: 1.3.0
          pip: 23.2.1
   setuptools: 68.0.0
        numpy: 1.24.3
        scipy: 1.11.2
       Cython: None
       pandas: 2.1.0
   matplotlib: 3.7.2
       joblib: 1.3.2
threadpoolctl: 3.2.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
    num_threads: 32
         prefix: libopenblas
       filepath: /home/guihuan/.conda/envs/py39/lib/python3.9/site-packages/numpy.libs/libopenblas64_p-r0-15028c96.3.21.so
        version: 0.3.21
threading_layer: pthreads
   architecture: Haswell

       user_api: openmp
   internal_api: openmp
    num_threads: 32
         prefix: libgomp
       filepath: /home/guihuan/.conda/envs/py39/lib/python3.9/site-packages/scikit_learn.libs/libgomp-a34b3233.so.1.0.0
        version: None

       user_api: blas
   internal_api: openblas
    num_threads: 32
         prefix: libopenblas
       filepath: /home/guihuan/.conda/envs/py39/lib/python3.9/site-packages/scipy.libs/libopenblasp-r0-23e5df77.3.21.dev.so
        version: 0.3.21.dev
threading_layer: pthreads
   architecture: Haswell
```

COMMENT:
Closing as a duplicate of https://github.com/scikit-learn/scikit-learn/issues/19547

Labels: Bug, Needs Triage
Question: Expanding the ERA Split Logic

Hi Jeffery,

I want to experiment by expanding the era splitting criterion and I wonder where the right place to implement that is. 
The current implementation defines the era wise gain as the mean over all eras

![image](https://github.com/scikit-learn/scikit-learn/assets/1447101/06176b7a-f19d-41b2-9550-880db2431081)

And then the Boltzmann operator afterwards. The boltzmann can stay as it is, but I want to experiment on the mean of all eras. 
Can you point me to where this is implemented?
Is it this file

https://github.com/jefferythewind/scikit-learn-erasplit/blob/era_splitting/sklearn/ensemble/_hist_gradient_boosting/era_splitting.pyx

Or even the histogram?

https://github.com/jefferythewind/scikit-learn-erasplit/blob/era_splitting/sklearn/ensemble/_hist_gradient_boosting/era_histogram.pyx

Thx!

COMMENT:
It looks like you want to ask this question in this repo: https://github.com/jefferythewind/scikit-learn-erasplit.

Feel free to reopen if I missed something.

Labels: Needs Triage
Question: Expanding the ERA Split Logic

Hi Jeffery,

I want to experiment by expanding the era splitting criterion and I wonder where the right place to implement that is. 
The current implementation defines the era wise gain as the mean over all eras

![image](https://github.com/scikit-learn/scikit-learn/assets/1447101/06176b7a-f19d-41b2-9550-880db2431081)

And then the Boltzmann operator afterwards. The boltzmann can stay as it is, but I want to experiment on the mean of all eras. 
Can you point me to where this is implemented?
Is it this file

https://github.com/jefferythewind/scikit-learn-erasplit/blob/era_splitting/sklearn/ensemble/_hist_gradient_boosting/era_splitting.pyx

Or even the histogram?

https://github.com/jefferythewind/scikit-learn-erasplit/blob/era_splitting/sklearn/ensemble/_hist_gradient_boosting/era_histogram.pyx

Thx!

COMMENT:
I am very sorry for the spam!

Labels: Needs Triage
Routing metadata to the `response_method` used by a scorer

### Describe the workflow you want to enable

I would like to pass sample properties to the response method (eg `predict`) called by a scorer.
For example, the `fairlearn` package has a `ThresholdOptimizer` estimator which needs (in addition to X and y) the `sensitive_features` argument both for fit and predict.

AFAICT I can pass arguments to the score function (the metric), but not to the response method of the estimator.

```python
import numpy as np
import sklearn
from sklearn.dummy import DummyClassifier
from sklearn.metrics import accuracy_score, make_scorer
from fairlearn.postprocessing import ThresholdOptimizer
from fairlearn.metrics import demographic_parity_difference


sklearn.set_config(enable_metadata_routing=True)

rng = np.random.default_rng(0)
X = rng.normal(size=(10, 3))
y = rng.integers(0, 2, size=X.shape[0])
sensitive = rng.integers(0, 2, size=X.shape[0])

classifier = (
    ThresholdOptimizer(estimator=DummyClassifier(), predict_method="auto")
    .set_fit_request(sensitive_features=True)
    .set_predict_request(sensitive_features=True)
    .fit(X, y, sensitive_features=sensitive)
)

scoring = make_scorer(accuracy_score)
scoring(classifier, X, y, sensitive_features=sensitive) # TypeError: predict() missing 1 argument -- how could I pass `sensitive_features to predict() ?

# passing arguments to the score function (demographic_parity_difference) is OK
classifier = DummyClassifier().fit(X, y)
scoring = make_scorer(
    demographic_parity_difference, greater_is_better=False
).set_score_request(sensitive_features=True)

scoring(classifier, X, y, sensitive_features=sensitive)

```

This also applies when using a scorer indirectly, for example in `cross_validate`

### Describe your proposed solution

Maybe the scorers could have a method like `set_predict_request` or `set_response_request` to specify which parameters should be forwarded to the response method?

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

_No response_

### Additional context

https://fairlearn.org/v0.9/api_reference/generated/fairlearn.postprocessing.ThresholdOptimizer.html
https://fairlearn.org/v0.9/api_reference/generated/fairlearn.metrics.demographic_parity_difference.html

COMMENT:
So for `fairlearn`, the scorers can themselves be routers and report the metadata required by the `response_method` as requested by the scorer, and things should work out of the box for tools we've implemented the routing for here in scikit-learn.

As for scikit-learn scorers themselves, yes, we should make this happen, but it's not gonna be an easy one I think.

Labels: New Feature, Metadata Routing
Routing metadata to the `response_method` used by a scorer

### Describe the workflow you want to enable

I would like to pass sample properties to the response method (eg `predict`) called by a scorer.
For example, the `fairlearn` package has a `ThresholdOptimizer` estimator which needs (in addition to X and y) the `sensitive_features` argument both for fit and predict.

AFAICT I can pass arguments to the score function (the metric), but not to the response method of the estimator.

```python
import numpy as np
import sklearn
from sklearn.dummy import DummyClassifier
from sklearn.metrics import accuracy_score, make_scorer
from fairlearn.postprocessing import ThresholdOptimizer
from fairlearn.metrics import demographic_parity_difference


sklearn.set_config(enable_metadata_routing=True)

rng = np.random.default_rng(0)
X = rng.normal(size=(10, 3))
y = rng.integers(0, 2, size=X.shape[0])
sensitive = rng.integers(0, 2, size=X.shape[0])

classifier = (
    ThresholdOptimizer(estimator=DummyClassifier(), predict_method="auto")
    .set_fit_request(sensitive_features=True)
    .set_predict_request(sensitive_features=True)
    .fit(X, y, sensitive_features=sensitive)
)

scoring = make_scorer(accuracy_score)
scoring(classifier, X, y, sensitive_features=sensitive) # TypeError: predict() missing 1 argument -- how could I pass `sensitive_features to predict() ?

# passing arguments to the score function (demographic_parity_difference) is OK
classifier = DummyClassifier().fit(X, y)
scoring = make_scorer(
    demographic_parity_difference, greater_is_better=False
).set_score_request(sensitive_features=True)

scoring(classifier, X, y, sensitive_features=sensitive)

```

This also applies when using a scorer indirectly, for example in `cross_validate`

### Describe your proposed solution

Maybe the scorers could have a method like `set_predict_request` or `set_response_request` to specify which parameters should be forwarded to the response method?

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

_No response_

### Additional context

https://fairlearn.org/v0.9/api_reference/generated/fairlearn.postprocessing.ThresholdOptimizer.html
https://fairlearn.org/v0.9/api_reference/generated/fairlearn.metrics.demographic_parity_difference.html

COMMENT:
We have the issue in `TunedThresholdClassifierCV` now. I'll put it in my TODO task for the next release.

Labels: New Feature, Metadata Routing
Bug in utils/multiclass.py/_ovr_decision_function

### Describe the workflow you want to enable

Dear scikit learn developpers,

I think the implementation of `_ovr_decision_function` in utils
/multiclass.py doesn't work properly when the parameter `confidences` is probability. While as the documentation suggests, it can be a probability .

```
confidences : array-like of shape (n_samples, n_classifiers)
        Decision functions or predicted probabilities for positive class
        for each binary classifier.
```

The problem is the following two lines of codes

```
sum_of_confidences[:, i] -= confidences[:, k]
sum_of_confidences[:, j] += confidences[:, k]
```

In this context, there is a binary classifier for class `i` vs `j`. And `j` is the positive class. 

If `confidences` is "decision_function", then it works. Because if "decision funtion" is negative, it means the classifier thinks the negatve class `i` is more possible. And the `-=` will increase the `sum_of_confidences` of `i`, and decrease the `sum_of_confidences` of `j`.

However, if  `confidences` is "probability", it doesn't work. Because probability is always greater than zero. So the `sum_of_confidences` of `i` will always decrease, even when `i` is more likely to happend (prob of `j` < 0.5).




### Describe your proposed solution

"decision_function" is centered at 0, while "probability" is centerd at 0.5. These two cases should be handled seperately.

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

_No response_

### Additional context

_No response_

COMMENT:
You argument seems logical. Would you be able to show the bug with an estimator. For instance `DecisionTreeClassifier` only has a `predict_proba` and would trigger the bug.

Labels: Bug
Bug in utils/multiclass.py/_ovr_decision_function

### Describe the workflow you want to enable

Dear scikit learn developpers,

I think the implementation of `_ovr_decision_function` in utils
/multiclass.py doesn't work properly when the parameter `confidences` is probability. While as the documentation suggests, it can be a probability .

```
confidences : array-like of shape (n_samples, n_classifiers)
        Decision functions or predicted probabilities for positive class
        for each binary classifier.
```

The problem is the following two lines of codes

```
sum_of_confidences[:, i] -= confidences[:, k]
sum_of_confidences[:, j] += confidences[:, k]
```

In this context, there is a binary classifier for class `i` vs `j`. And `j` is the positive class. 

If `confidences` is "decision_function", then it works. Because if "decision funtion" is negative, it means the classifier thinks the negatve class `i` is more possible. And the `-=` will increase the `sum_of_confidences` of `i`, and decrease the `sum_of_confidences` of `j`.

However, if  `confidences` is "probability", it doesn't work. Because probability is always greater than zero. So the `sum_of_confidences` of `i` will always decrease, even when `i` is more likely to happend (prob of `j` < 0.5).




### Describe your proposed solution

"decision_function" is centered at 0, while "probability" is centerd at 0.5. These two cases should be handled seperately.

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

_No response_

### Additional context

_No response_

COMMENT:
@glemaitre  @newyorker123, could I work on this issue? I would like to conduct further research on it and attempt to find a solution. This looks like a great opportunity for me to contribute to this project.

Labels: Bug
Bug in utils/multiclass.py/_ovr_decision_function

### Describe the workflow you want to enable

Dear scikit learn developpers,

I think the implementation of `_ovr_decision_function` in utils
/multiclass.py doesn't work properly when the parameter `confidences` is probability. While as the documentation suggests, it can be a probability .

```
confidences : array-like of shape (n_samples, n_classifiers)
        Decision functions or predicted probabilities for positive class
        for each binary classifier.
```

The problem is the following two lines of codes

```
sum_of_confidences[:, i] -= confidences[:, k]
sum_of_confidences[:, j] += confidences[:, k]
```

In this context, there is a binary classifier for class `i` vs `j`. And `j` is the positive class. 

If `confidences` is "decision_function", then it works. Because if "decision funtion" is negative, it means the classifier thinks the negatve class `i` is more possible. And the `-=` will increase the `sum_of_confidences` of `i`, and decrease the `sum_of_confidences` of `j`.

However, if  `confidences` is "probability", it doesn't work. Because probability is always greater than zero. So the `sum_of_confidences` of `i` will always decrease, even when `i` is more likely to happend (prob of `j` < 0.5).




### Describe your proposed solution

"decision_function" is centered at 0, while "probability" is centerd at 0.5. These two cases should be handled seperately.

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

_No response_

### Additional context

_No response_

COMMENT:
@glemaitre @newyorker123 @LC1243 I'd like to work on this but do not want to produce duplicates. Can I take a look and create a PR?

Labels: Bug
Bug in utils/multiclass.py/_ovr_decision_function

### Describe the workflow you want to enable

Dear scikit learn developpers,

I think the implementation of `_ovr_decision_function` in utils
/multiclass.py doesn't work properly when the parameter `confidences` is probability. While as the documentation suggests, it can be a probability .

```
confidences : array-like of shape (n_samples, n_classifiers)
        Decision functions or predicted probabilities for positive class
        for each binary classifier.
```

The problem is the following two lines of codes

```
sum_of_confidences[:, i] -= confidences[:, k]
sum_of_confidences[:, j] += confidences[:, k]
```

In this context, there is a binary classifier for class `i` vs `j`. And `j` is the positive class. 

If `confidences` is "decision_function", then it works. Because if "decision funtion" is negative, it means the classifier thinks the negatve class `i` is more possible. And the `-=` will increase the `sum_of_confidences` of `i`, and decrease the `sum_of_confidences` of `j`.

However, if  `confidences` is "probability", it doesn't work. Because probability is always greater than zero. So the `sum_of_confidences` of `i` will always decrease, even when `i` is more likely to happend (prob of `j` < 0.5).




### Describe your proposed solution

"decision_function" is centered at 0, while "probability" is centerd at 0.5. These two cases should be handled seperately.

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

_No response_

### Additional context

_No response_

COMMENT:
Hi @kyrajeep , thank you for your interest in working on this. I wanted to let you know that I have already created a Pull Request (#28739) that addresses this issue. It is currently awaiting review.
If you have any suggestions, I would really appreciate them.

Labels: Bug
Bug in utils/multiclass.py/_ovr_decision_function

### Describe the workflow you want to enable

Dear scikit learn developpers,

I think the implementation of `_ovr_decision_function` in utils
/multiclass.py doesn't work properly when the parameter `confidences` is probability. While as the documentation suggests, it can be a probability .

```
confidences : array-like of shape (n_samples, n_classifiers)
        Decision functions or predicted probabilities for positive class
        for each binary classifier.
```

The problem is the following two lines of codes

```
sum_of_confidences[:, i] -= confidences[:, k]
sum_of_confidences[:, j] += confidences[:, k]
```

In this context, there is a binary classifier for class `i` vs `j`. And `j` is the positive class. 

If `confidences` is "decision_function", then it works. Because if "decision funtion" is negative, it means the classifier thinks the negatve class `i` is more possible. And the `-=` will increase the `sum_of_confidences` of `i`, and decrease the `sum_of_confidences` of `j`.

However, if  `confidences` is "probability", it doesn't work. Because probability is always greater than zero. So the `sum_of_confidences` of `i` will always decrease, even when `i` is more likely to happend (prob of `j` < 0.5).




### Describe your proposed solution

"decision_function" is centered at 0, while "probability" is centerd at 0.5. These two cases should be handled seperately.

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

_No response_

### Additional context

_No response_

COMMENT:
Thank you for letting me know! I am not sure I will have the time to take a look, but I appreciate your contribution :)

Labels: Bug
Is the time complexity of neural network in the doc right?

### Describe the issue linked to the documentation

Are you sure the [time complexity](https://scikit-learn.org/stable/modules/neural_networks_supervised.html#complexity) is right? Exponential complexity with respect to the number of layers rather than polynomial?
![image](https://github.com/scikit-learn/scikit-learn/assets/47685165/e183f52f-f03e-41d8-8192-74e9a410faf5)



### Suggest a potential alternative/fix

I notice a different answer from [here](https://ai.stackexchange.com/questions/5728/what-is-the-time-complexity-for-training-a-neural-network-using-back-propagation/20281?newreg=92fccd4d6b51442db4e6d1dcc1dcfccf), and I think it right.

COMMENT:
I agree it's a mistake. I think it should be something like:

```
O(i . n . (m . h + (k - 1) . h . h + h . o))
```

where `n` is the number of training data points.

Would you be interested in opening a PR to fix it?

Labels: Bug, Documentation
Is the time complexity of neural network in the doc right?

### Describe the issue linked to the documentation

Are you sure the [time complexity](https://scikit-learn.org/stable/modules/neural_networks_supervised.html#complexity) is right? Exponential complexity with respect to the number of layers rather than polynomial?
![image](https://github.com/scikit-learn/scikit-learn/assets/47685165/e183f52f-f03e-41d8-8192-74e9a410faf5)



### Suggest a potential alternative/fix

I notice a different answer from [here](https://ai.stackexchange.com/questions/5728/what-is-the-time-complexity-for-training-a-neural-network-using-back-propagation/20281?newreg=92fccd4d6b51442db4e6d1dcc1dcfccf), and I think it right.

COMMENT:
Cannot find a readme that matches. If it's okay with you, where would you go to change this?

Labels: Bug, Documentation
Is the time complexity of neural network in the doc right?

### Describe the issue linked to the documentation

Are you sure the [time complexity](https://scikit-learn.org/stable/modules/neural_networks_supervised.html#complexity) is right? Exponential complexity with respect to the number of layers rather than polynomial?
![image](https://github.com/scikit-learn/scikit-learn/assets/47685165/e183f52f-f03e-41d8-8192-74e9a410faf5)



### Suggest a potential alternative/fix

I notice a different answer from [here](https://ai.stackexchange.com/questions/5728/what-is-the-time-complexity-for-training-a-neural-network-using-back-propagation/20281?newreg=92fccd4d6b51442db4e6d1dcc1dcfccf), and I think it right.

COMMENT:
I'm new here. Can I take this?

Labels: Bug, Documentation
DOC doc build sphinx version link out-dated again

### Describe the issue linked to the documentation

The link to the sphinx versions for doc build at the end of [*Building the documentation*](https://scikit-learn.org/dev/developers/contributing.html#building-the-documentation) is again out-dated, with sphinx version unpinned in #27656.

![image](https://github.com/scikit-learn/scikit-learn/assets/108576690/09121218-25dc-4f4d-babb-403732ad5f71)

![image](https://github.com/scikit-learn/scikit-learn/assets/108576690/c1e2fae3-98d8-432f-a1d5-0b3e1b08f389)


### Suggest a potential alternative/fix

Maybe use this link instead? https://github.com/search?q=repo%3Ascikit-learn%2Fscikit-learn+sphinx+path%3Abuild_tools%2Fcircle%2Fdoc_linux-64_conda.lock&type=code

COMMENT:
It's not that it is outdated but that right now sphinx version is unconstrained, so using the latest sphinx version should be fine. I agree it can be a bit confusing if you are looking for an exact version.

Linking to the lock file could be an option, as I mentioned in https://github.com/scikit-learn/scikit-learn/issues/27643#issuecomment-1775359434. I just realised that regex is supported by github search so the following link would be clear:
https://github.com/search?q=repo%3Ascikit-learn%2Fscikit-learn+%2F%5C%2Fsphinx-%5B0-9.%5D%2B%2F+path%3Abuild_tools%2Fcircle%2Fdoc_linux-64_conda.lock&type=code

Which gives a single line with sphinx + version highlighted:
![image](https://github.com/scikit-learn/scikit-learn/assets/1680079/54e05e0f-24b4-485a-8cce-e7e19a94f0fb)

Originally I was not sure that linking to the lock file was worth it, but using the link with the regex above, I now think it is, so PR more than welcome!

Labels: Documentation, Needs Triage
PR: Polynomial Chaos Expansions with no responses???

### Describe the workflow you want to enable

.

### Describe your proposed solution

.

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

_No response_

### Additional context

Why no one comment this PR https://github.com/scikit-learn/scikit-learn/pull/27842 ?
Its a good work (yes/no) ?  If yes, when will implemented in scikit-learn? in the next scikit-learn 1.4 ?
I'm not the author, but i think this work needs any word. The author have a lot of work and time in this PR.

COMMENT:
@celestinoxp Please refrain from opening such spmamy / redundant issues just to catch the attention of already overwhelmed reviewers. A comment on the issue is enough.

Labels: New Feature, Needs Triage