Talip7/scikit-learn-issues-multilabel huggingface dataset:
[RFC] Allow handling of NaNs in multi-task Random Forests

### Describe the workflow you want to enable

 Currently the RFR implementation is only capable of handling dense multi-task problems is there any scope to change the underlying algorithm to handle NaNs as a special case or would this break the API given that it might extend to allowing NaNs in the single class case? 

The hypothesis is that I may benefit from knowing the information about the available labels in the multi-task model even though I am missing labels for some tasks.

### Describe your proposed solution

boolean flag in the constructor that allows NaNs to be ignored when calculating the impurity.

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

_No response_

### Additional context

```python
>>> import numpy as np
>>> from sklearn.ensemble import RandomForestRegressor
>>> rfr=RandomForestRegressor()
>>> X = np.random.randn(5,10)
>>> y = np.random.randn(5,2)
>>> y[4,1]=np.nan
>>> rfr.fit(X, y)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/chemix-rhys/opt/miniconda3/envs/chemix-py310/lib/python3.10/site-packages/sklearn/base.py", line 1151, in wrapper
    return fit_method(estimator, *args, **kwargs)
  File "/Users/chemix-rhys/opt/miniconda3/envs/chemix-py310/lib/python3.10/site-packages/sklearn/ensemble/_forest.py", line 348, in fit
    X, y = self._validate_data(
  File "/Users/chemix-rhys/opt/miniconda3/envs/chemix-py310/lib/python3.10/site-packages/sklearn/base.py", line 621, in _validate_data
    X, y = check_X_y(X, y, **check_params)
  File "/Users/chemix-rhys/opt/miniconda3/envs/chemix-py310/lib/python3.10/site-packages/sklearn/utils/validation.py", line 1163, in check_X_y
    y = _check_y(y, multi_output=multi_output, y_numeric=y_numeric, estimator=estimator)
  File "/Users/chemix-rhys/opt/miniconda3/envs/chemix-py310/lib/python3.10/site-packages/sklearn/utils/validation.py", line 1173, in _check_y
    y = check_array(
  File "/Users/chemix-rhys/opt/miniconda3/envs/chemix-py310/lib/python3.10/site-packages/sklearn/utils/validation.py", line 959, in check_array
    _assert_all_finite(
  File "/Users/chemix-rhys/opt/miniconda3/envs/chemix-py310/lib/python3.10/site-packages/sklearn/utils/validation.py", line 124, in _assert_all_finite
    _assert_all_finite_element_wise(
  File "/Users/chemix-rhys/opt/miniconda3/envs/chemix-py310/lib/python3.10/site-packages/sklearn/utils/validation.py", line 173, in _assert_all_finite_element_wise
    raise ValueError(msg_err)
ValueError: Input y contains NaN.
```

COMMENT:
Ok, thank you I will take a look at those

Labels: New Feature
[RFC] Allow handling of NaNs in multi-task Random Forests

### Describe the workflow you want to enable

 Currently the RFR implementation is only capable of handling dense multi-task problems is there any scope to change the underlying algorithm to handle NaNs as a special case or would this break the API given that it might extend to allowing NaNs in the single class case? 

The hypothesis is that I may benefit from knowing the information about the available labels in the multi-task model even though I am missing labels for some tasks.

### Describe your proposed solution

boolean flag in the constructor that allows NaNs to be ignored when calculating the impurity.

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

_No response_

### Additional context

```python
>>> import numpy as np
>>> from sklearn.ensemble import RandomForestRegressor
>>> rfr=RandomForestRegressor()
>>> X = np.random.randn(5,10)
>>> y = np.random.randn(5,2)
>>> y[4,1]=np.nan
>>> rfr.fit(X, y)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/chemix-rhys/opt/miniconda3/envs/chemix-py310/lib/python3.10/site-packages/sklearn/base.py", line 1151, in wrapper
    return fit_method(estimator, *args, **kwargs)
  File "/Users/chemix-rhys/opt/miniconda3/envs/chemix-py310/lib/python3.10/site-packages/sklearn/ensemble/_forest.py", line 348, in fit
    X, y = self._validate_data(
  File "/Users/chemix-rhys/opt/miniconda3/envs/chemix-py310/lib/python3.10/site-packages/sklearn/base.py", line 621, in _validate_data
    X, y = check_X_y(X, y, **check_params)
  File "/Users/chemix-rhys/opt/miniconda3/envs/chemix-py310/lib/python3.10/site-packages/sklearn/utils/validation.py", line 1163, in check_X_y
    y = _check_y(y, multi_output=multi_output, y_numeric=y_numeric, estimator=estimator)
  File "/Users/chemix-rhys/opt/miniconda3/envs/chemix-py310/lib/python3.10/site-packages/sklearn/utils/validation.py", line 1173, in _check_y
    y = check_array(
  File "/Users/chemix-rhys/opt/miniconda3/envs/chemix-py310/lib/python3.10/site-packages/sklearn/utils/validation.py", line 959, in check_array
    _assert_all_finite(
  File "/Users/chemix-rhys/opt/miniconda3/envs/chemix-py310/lib/python3.10/site-packages/sklearn/utils/validation.py", line 124, in _assert_all_finite
    _assert_all_finite_element_wise(
  File "/Users/chemix-rhys/opt/miniconda3/envs/chemix-py310/lib/python3.10/site-packages/sklearn/utils/validation.py", line 173, in _assert_all_finite_element_wise
    raise ValueError(msg_err)
ValueError: Input y contains NaN.
```

COMMENT:
tagging related: https://github.com/scikit-learn/scikit-learn/issues/5870

Labels: New Feature
[RFC] Allow handling of NaNs in multi-task Random Forests

### Describe the workflow you want to enable

 Currently the RFR implementation is only capable of handling dense multi-task problems is there any scope to change the underlying algorithm to handle NaNs as a special case or would this break the API given that it might extend to allowing NaNs in the single class case? 

The hypothesis is that I may benefit from knowing the information about the available labels in the multi-task model even though I am missing labels for some tasks.

### Describe your proposed solution

boolean flag in the constructor that allows NaNs to be ignored when calculating the impurity.

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

_No response_

### Additional context

```python
>>> import numpy as np
>>> from sklearn.ensemble import RandomForestRegressor
>>> rfr=RandomForestRegressor()
>>> X = np.random.randn(5,10)
>>> y = np.random.randn(5,2)
>>> y[4,1]=np.nan
>>> rfr.fit(X, y)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/chemix-rhys/opt/miniconda3/envs/chemix-py310/lib/python3.10/site-packages/sklearn/base.py", line 1151, in wrapper
    return fit_method(estimator, *args, **kwargs)
  File "/Users/chemix-rhys/opt/miniconda3/envs/chemix-py310/lib/python3.10/site-packages/sklearn/ensemble/_forest.py", line 348, in fit
    X, y = self._validate_data(
  File "/Users/chemix-rhys/opt/miniconda3/envs/chemix-py310/lib/python3.10/site-packages/sklearn/base.py", line 621, in _validate_data
    X, y = check_X_y(X, y, **check_params)
  File "/Users/chemix-rhys/opt/miniconda3/envs/chemix-py310/lib/python3.10/site-packages/sklearn/utils/validation.py", line 1163, in check_X_y
    y = _check_y(y, multi_output=multi_output, y_numeric=y_numeric, estimator=estimator)
  File "/Users/chemix-rhys/opt/miniconda3/envs/chemix-py310/lib/python3.10/site-packages/sklearn/utils/validation.py", line 1173, in _check_y
    y = check_array(
  File "/Users/chemix-rhys/opt/miniconda3/envs/chemix-py310/lib/python3.10/site-packages/sklearn/utils/validation.py", line 959, in check_array
    _assert_all_finite(
  File "/Users/chemix-rhys/opt/miniconda3/envs/chemix-py310/lib/python3.10/site-packages/sklearn/utils/validation.py", line 124, in _assert_all_finite
    _assert_all_finite_element_wise(
  File "/Users/chemix-rhys/opt/miniconda3/envs/chemix-py310/lib/python3.10/site-packages/sklearn/utils/validation.py", line 173, in _assert_all_finite_element_wise
    raise ValueError(msg_err)
ValueError: Input y contains NaN.
```

COMMENT:
@glemaitre you removed the "Needs Triage" tag here, but I'm not sure if we are clear on how to move forward here.

Labels: New Feature
Add __get_item__() to ColumnTransformer

### Describe the workflow you want to enable

This is really an extension to https://github.com/scikit-learn/scikit-learn/issues/24906 to retrieve state of column transformer components by name like other composite components.

### Describe your proposed solution

For example: 
```python
model = Pipeline(steps=[
   (“step1”, Component()),
   (“step2” ColumnTransformer(transformers=[
       (“part2a”, Component(), ["column1"]),
       (“part2b”, Component(), ["column1", "column2"]),
   ])),
])
```

would be accessed as:
```python
component, columns = model[“step2”][“part2a”]
```

### Describe alternatives you've considered, if relevant

Currently this is how a user can fetch a component:
```python
component = model[“step2”].transformers[0][1] 
```
This works but is brittle as users need to know implementation details such as of the `transformers` reference attribute or `.transformers_` fitted attribute name of the container as well as the often irrelevant index order `[0]` in which the interested component was declared.

### Additional context

_No response_

COMMENT:
Unlike `FeatureUnion` & `Pipeline` an extra detail is that the `ColumnTransformer` keeps track of both the reference & fitted list of transformers. I think most use cases would want to look into the state of the object & retrieval should attempt fetching the fitted `.transformers_` first if available else fallback to (perhaps to a copy of) the reference `.transformers`. Thoughts?

Labels: New Feature, Needs Triage
Add __get_item__() to ColumnTransformer

### Describe the workflow you want to enable

This is really an extension to https://github.com/scikit-learn/scikit-learn/issues/24906 to retrieve state of column transformer components by name like other composite components.

### Describe your proposed solution

For example: 
```python
model = Pipeline(steps=[
   (“step1”, Component()),
   (“step2” ColumnTransformer(transformers=[
       (“part2a”, Component(), ["column1"]),
       (“part2b”, Component(), ["column1", "column2"]),
   ])),
])
```

would be accessed as:
```python
component, columns = model[“step2”][“part2a”]
```

### Describe alternatives you've considered, if relevant

Currently this is how a user can fetch a component:
```python
component = model[“step2”].transformers[0][1] 
```
This works but is brittle as users need to know implementation details such as of the `transformers` reference attribute or `.transformers_` fitted attribute name of the container as well as the often irrelevant index order `[0]` in which the interested component was declared.

### Additional context

_No response_

COMMENT:
Thank you for opening the issue! According to our [triaging guidelines](https://scikit-learn.org/dev/developers/bug_triaging.html#triaging-operations-for-members-of-the-core-and-contributor-experience-teams), I am closing this as a duplicate of https://github.com/scikit-learn/scikit-learn/issues/15346. You are welcome to continue the conversation there.

Labels: New Feature, Needs Triage
`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:
Not really a good answer, but this is related to another more general discussion in https://github.com/scikit-learn/scikit-learn/issues/19547.

Labels: Bug, Needs Triage
`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:
Hi @lesteve, I understand that my answer was quite basic and I should have done more research. I'll do better next time.

Labels: Bug, Needs Triage
`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:
@raj-pulapakura your answer was perfectly fine, thanks for this by the way!

With my comment, I was mostly trying to leave a note for us to remember that similar things have been discussed elsewhere.

Labels: Bug, Needs Triage
`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:
@lesteve Thanks for the clarification 😄.

Labels: Bug, Needs Triage