Talip7/scikit-learn-issues-multilabel huggingface dataset:
[FEAT] Let `importance_getter` from RFE accept test data for permutation importance

### Describe the workflow you want to enable

To recursively eliminate features, `permutation_importance` is a sensible method of feature importance as it satisfies $X_j \perp Y | X_{-j} \iff \texttt{PermutationImportance}(X_j) = 0$ (see [Reyero Lobo et al. (2025)](https://arxiv.org/pdf/2507.17306)).

However, with the current implementations of `RFE` and `RFECV`, it is not possible to use permutation importance. Indeed the `importance_getter` parameter, when a callable, can only be given a model, but as the features are removed from the dataset, the `permutation_importance` method needs to know which columns of `X_test` to use for predicting.

### Describe your proposed solution

Let the `sklearn.feature_selection._base._get_feature_importances` method accept column indices that are passed to the `importance_getter` callable so that it can extract the relevant columns of the its test dataset.

Notes:
- To be backward compatible, it needs to inspect the input parameters of `importance_getter` and only provide feature indices when it can accept them.
- The function `_get_feature_importances` is also used by `SelectFromModel` which could then also benefit from this change.

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

Let `RFE` and `RFECV` accept optional `X_test` and `y_test` parameters in the `fit` that are given to the `importance_getter` through the `sklearn.feature_selection._base._get_feature_importances` method.

### Additional context

We discussed it with @ogrisel and @glemaitre and think that it is a good thing to include but we are open to discussion/suggestions.

COMMENT:
Hi, I’m interested in this issue and would like to work on it. Could you please assign it to me? Thank you!

Labels: New Feature, module:inspection
⚠️ CI failed on Linux_Runs.pylatest_conda_forge_mkl (last failure: Sep 16, 2025) ⚠️

**CI failed on [Linux_Runs.pylatest_conda_forge_mkl](https://dev.azure.com/scikit-learn/scikit-learn/_build/results?buildId=80046&view=logs&j=dde5042c-7464-5d47-9507-31bdd2ee0a3a)** (Sep 16, 2025)
- Test Collection Failure

COMMENT:
## CI is no longer failing! ✅

[Successful run](https://dev.azure.com/scikit-learn/scikit-learn/_build/results?buildId=80046&view=logs&j=de937867-5818-5907-5645-0b22541236da) on Sep 16, 2025

Labels: Needs Triage
MNT test_tree.py::test_diabetes_underfit is flaky: it fails when changing the random seed

### Describe the bug

`test_tree.py::test_diabetes_underfit` is flaky: it fails when changing the random seed.

I will open a PR to fix it. 

### Steps/Code to Reproduce

Change the random seed in `sklearn/tree/tests/test_tree.py::test_diabetes_underfit` and run it with pytest. Almost any other seed will make at least one of the 8 generated tests (by `@pytest.mark.parametrize`) break.

### Expected Results

Test passes for any random seed (or at least for ~99.9% of them).

### Actual Results

Tests break, with for instance:

```
FAILED sklearn/tree/tests/test_tree.py::test_diabetes_underfit[friedman_mse-15-mean_squared_error-60-ExtraTreeRegressor-ExtraTreeRegressor] - assert 343.3070340521192 < 60
```

Or:

```
FAILED sklearn/tree/tests/test_tree.py::test_diabetes_underfit[absolute_error-20-mean_squared_error-60-ExtraTreeRegressor-ExtraTreeRegressor] - assert 0 < 0.0
```

### Versions

```shell
System:
    python: 3.12.11 (main, Aug 18 2025, 19:19:11) [Clang 20.1.4 ]
executable: /home/arthur/dev-perso/scikit-learn/sklearn-env/bin/python
   machine: Linux-6.14.0-29-generic-x86_64-with-glibc2.39

Python dependencies:
      sklearn: 1.8.dev0
          pip: None
   setuptools: 80.9.0
        numpy: 2.3.3
        scipy: 1.16.2
       Cython: 3.1.3
       pandas: 2.3.2
   matplotlib: 3.10.6
       joblib: 1.5.2
threadpoolctl: 3.6.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
    num_threads: 16
         prefix: libscipy_openblas
       filepath: /home/arthur/dev-perso/scikit-learn/sklearn-env/lib/python3.12/site-packages/numpy.libs/libscipy_openblas64_-8fb3d286.so
        version: 0.3.30
threading_layer: pthreads
   architecture: Haswell

       user_api: blas
   internal_api: openblas
    num_threads: 16
         prefix: libscipy_openblas
       filepath: /home/arthur/dev-perso/scikit-learn/sklearn-env/lib/python3.12/site-packages/scipy.libs/libscipy_openblas-b75cc656.so
        version: 0.3.29.dev
threading_layer: pthreads
   architecture: Haswell

       user_api: openmp
   internal_api: openmp
    num_threads: 16
         prefix: libgomp
       filepath: /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0
        version: None
```

COMMENT:
i would like take this issue

Labels: Bug, module:tree
MNT test_tree.py::test_diabetes_underfit is flaky: it fails when changing the random seed

### Describe the bug

`test_tree.py::test_diabetes_underfit` is flaky: it fails when changing the random seed.

I will open a PR to fix it. 

### Steps/Code to Reproduce

Change the random seed in `sklearn/tree/tests/test_tree.py::test_diabetes_underfit` and run it with pytest. Almost any other seed will make at least one of the 8 generated tests (by `@pytest.mark.parametrize`) break.

### Expected Results

Test passes for any random seed (or at least for ~99.9% of them).

### Actual Results

Tests break, with for instance:

```
FAILED sklearn/tree/tests/test_tree.py::test_diabetes_underfit[friedman_mse-15-mean_squared_error-60-ExtraTreeRegressor-ExtraTreeRegressor] - assert 343.3070340521192 < 60
```

Or:

```
FAILED sklearn/tree/tests/test_tree.py::test_diabetes_underfit[absolute_error-20-mean_squared_error-60-ExtraTreeRegressor-ExtraTreeRegressor] - assert 0 < 0.0
```

### Versions

```shell
System:
    python: 3.12.11 (main, Aug 18 2025, 19:19:11) [Clang 20.1.4 ]
executable: /home/arthur/dev-perso/scikit-learn/sklearn-env/bin/python
   machine: Linux-6.14.0-29-generic-x86_64-with-glibc2.39

Python dependencies:
      sklearn: 1.8.dev0
          pip: None
   setuptools: 80.9.0
        numpy: 2.3.3
        scipy: 1.16.2
       Cython: 3.1.3
       pandas: 2.3.2
   matplotlib: 3.10.6
       joblib: 1.5.2
threadpoolctl: 3.6.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
    num_threads: 16
         prefix: libscipy_openblas
       filepath: /home/arthur/dev-perso/scikit-learn/sklearn-env/lib/python3.12/site-packages/numpy.libs/libscipy_openblas64_-8fb3d286.so
        version: 0.3.30
threading_layer: pthreads
   architecture: Haswell

       user_api: blas
   internal_api: openblas
    num_threads: 16
         prefix: libscipy_openblas
       filepath: /home/arthur/dev-perso/scikit-learn/sklearn-env/lib/python3.12/site-packages/scipy.libs/libscipy_openblas-b75cc656.so
        version: 0.3.29.dev
threading_layer: pthreads
   architecture: Haswell

       user_api: openmp
   internal_api: openmp
    num_threads: 16
         prefix: libgomp
       filepath: /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0
        version: None
```

COMMENT:
Hi @nithish-74, sorry I already wrote a PR for this one 😅 

You can make a review of it though, it would be super appreciated 🙏 https://github.com/scikit-learn/scikit-learn/pull/32190

Labels: Bug, module:tree
Windows kernel crash when calling LinearRegression().fit().predict() on small dataset

### Describe the bug

Using `sklearn.linear_model.LinearRegression` on Windows 11 ,Lenovo Legion laptop ,intel i7 core with a very small dataset (46 samples × 5 features) causes the Jupyter Notebook kernel to immediately crash and restart. This happens consistently even in a fresh conda environment or with official Python + pip installation.

## To Reproduce

Steps to reproduce the behavior:

```python
import numpy as np
from sklearn.linear_model import LinearRegression




### Steps/Code to Reproduce

import pandas as pd
import numpy as np
from CBFV import composition
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import MinMaxScaler
from sklearn.preprocessing import normalize
from sklearn.model_selection import train_test_split
from sklearn.metrics import r2_score



X = np.random.rand(46, 5)
y = np.random.rand(46)

model = LinearRegression()
model.fit(X, y)
y_pred = model.predict(X)  # <- This triggers kernel crash

### Expected Results

can still be run in jupyter then i can finish my homwork qwq only 1 week left

### Actual Results

Kernel Restarting
The kernel for MLE5217/5_CBFV.ipynb appears to have died. It will restart automatically.

### Versions

```shell
System:
    python: 3.10.18 | packaged by Anaconda, Inc. | (main, Jun  5 2025, 13:08:55) [MSC v.1929 64 bit (AMD64)]
executable: D:\Anaconda3\envs\mle5217\python.exe
   machine: Windows-10-10.0.26100-SP0

Python dependencies:
      sklearn: 1.7.1
          pip: 25.1
   setuptools: 78.1.1
        numpy: 2.2.6
        scipy: 1.15.2
       Cython: None
       pandas: 2.3.1
   matplotlib: 3.10.5
       joblib: 1.5.1
threadpoolctl: 3.6.0

Built with OpenMP: True
```

COMMENT:
Thanks for reporting the issue, @1423166192-max.

I cannot reproduce the same issue on my Windows machine.

At first glance, the issue appears to be that the IPython kernel was not properly installed, which is causing it to crash when running the notebook. This does not seem to be a problem with scikit-learn’s code or documentation.

I would suggest trying the same code on Google Colab to see if the error persists, or if any error messages are raised by scikit-learn.

With that said, I’m closing this issue.

Labels: Bug, Needs Triage
Windows kernel crash when calling LinearRegression().fit().predict() on small dataset

### Describe the bug

Using `sklearn.linear_model.LinearRegression` on Windows 11 ,Lenovo Legion laptop ,intel i7 core with a very small dataset (46 samples × 5 features) causes the Jupyter Notebook kernel to immediately crash and restart. This happens consistently even in a fresh conda environment or with official Python + pip installation.

## To Reproduce

Steps to reproduce the behavior:

```python
import numpy as np
from sklearn.linear_model import LinearRegression




### Steps/Code to Reproduce

import pandas as pd
import numpy as np
from CBFV import composition
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import MinMaxScaler
from sklearn.preprocessing import normalize
from sklearn.model_selection import train_test_split
from sklearn.metrics import r2_score



X = np.random.rand(46, 5)
y = np.random.rand(46)

model = LinearRegression()
model.fit(X, y)
y_pred = model.predict(X)  # <- This triggers kernel crash

### Expected Results

can still be run in jupyter then i can finish my homwork qwq only 1 week left

### Actual Results

Kernel Restarting
The kernel for MLE5217/5_CBFV.ipynb appears to have died. It will restart automatically.

### Versions

```shell
System:
    python: 3.10.18 | packaged by Anaconda, Inc. | (main, Jun  5 2025, 13:08:55) [MSC v.1929 64 bit (AMD64)]
executable: D:\Anaconda3\envs\mle5217\python.exe
   machine: Windows-10-10.0.26100-SP0

Python dependencies:
      sklearn: 1.7.1
          pip: 25.1
   setuptools: 78.1.1
        numpy: 2.2.6
        scipy: 1.15.2
       Cython: None
       pandas: 2.3.1
   matplotlib: 3.10.5
       joblib: 1.5.1
threadpoolctl: 3.6.0

Built with OpenMP: True
```

COMMENT:
> 感谢您报告该问题，。
> 
> 我无法在我的 Windows 计算机上重现相同的问题。
> 
> 乍一看，问题似乎是 IPython 内核未正确安装，这导致它在运行笔记本时崩溃。这似乎不是 scikit-learn 的代码或文档的问题。
> 
> 我建议在 Google Colab 上尝试相同的代码，看看错误是否仍然存在，或者 scikit-learn 是否引发了任何错误消息。
> 
> 话虽如此，我将结束这个问题。

Not the ipython issue, its complete. Seems to have relationship with certain CPU, on the ML class of 200  people there's also people encounter same problem like me Using Exactly the same laptop

Labels: Bug, Needs Triage
Windows kernel crash when calling LinearRegression().fit().predict() on small dataset

### Describe the bug

Using `sklearn.linear_model.LinearRegression` on Windows 11 ,Lenovo Legion laptop ,intel i7 core with a very small dataset (46 samples × 5 features) causes the Jupyter Notebook kernel to immediately crash and restart. This happens consistently even in a fresh conda environment or with official Python + pip installation.

## To Reproduce

Steps to reproduce the behavior:

```python
import numpy as np
from sklearn.linear_model import LinearRegression




### Steps/Code to Reproduce

import pandas as pd
import numpy as np
from CBFV import composition
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import MinMaxScaler
from sklearn.preprocessing import normalize
from sklearn.model_selection import train_test_split
from sklearn.metrics import r2_score



X = np.random.rand(46, 5)
y = np.random.rand(46)

model = LinearRegression()
model.fit(X, y)
y_pred = model.predict(X)  # <- This triggers kernel crash

### Expected Results

can still be run in jupyter then i can finish my homwork qwq only 1 week left

### Actual Results

Kernel Restarting
The kernel for MLE5217/5_CBFV.ipynb appears to have died. It will restart automatically.

### Versions

```shell
System:
    python: 3.10.18 | packaged by Anaconda, Inc. | (main, Jun  5 2025, 13:08:55) [MSC v.1929 64 bit (AMD64)]
executable: D:\Anaconda3\envs\mle5217\python.exe
   machine: Windows-10-10.0.26100-SP0

Python dependencies:
      sklearn: 1.7.1
          pip: 25.1
   setuptools: 78.1.1
        numpy: 2.2.6
        scipy: 1.15.2
       Cython: None
       pandas: 2.3.1
   matplotlib: 3.10.5
       joblib: 1.5.1
threadpoolctl: 3.6.0

Built with OpenMP: True
```

COMMENT:
> 感谢您报告该问题，。
> 
> 我无法在我的 Windows 计算机上重现相同的问题。
> 
> 乍一看，问题似乎是 IPython 内核未正确安装，这导致它在运行笔记本时崩溃。这似乎不是 scikit-learn 的代码或文档的问题。
> 
> 我建议在 Google Colab 上尝试相同的代码，看看错误是否仍然存在，或者 scikit-learn 是否引发了任何错误消息。
> 
> 话虽如此，我将结束这个问题。

run it on google colab, no problem

Labels: Bug, Needs Triage
⚠️ CI failed on Linux.pylatest_pip_openblas_pandas (last failure: Sep 30, 2025) ⚠️

**CI is still failing on [Linux.pylatest_pip_openblas_pandas](https://dev.azure.com/scikit-learn/scikit-learn/_build/results?buildId=80535&view=logs&j=78a0bf4f-79e5-5387-94ec-13e67d216d6e)** (Sep 30, 2025)
- test_fit_transform[98]

COMMENT:
## CI is no longer failing! ✅

[Successful run](https://dev.azure.com/scikit-learn/scikit-learn/_build/results?buildId=80574&view=logs&j=78a0bf4f-79e5-5387-94ec-13e67d216d6e) on Oct 01, 2025

Labels: Bug, module:test-suite
⚠️ CI failed on Linux.pylatest_pip_openblas_pandas (last failure: Sep 30, 2025) ⚠️

**CI is still failing on [Linux.pylatest_pip_openblas_pandas](https://dev.azure.com/scikit-learn/scikit-learn/_build/results?buildId=80535&view=logs&j=78a0bf4f-79e5-5387-94ec-13e67d216d6e)** (Sep 30, 2025)
- test_fit_transform[98]

COMMENT:
Looks like a test too sensitive to the random seed. I confirmed it locally and found errors for a few other random seeds.

Labels: Bug, module:test-suite
⚠️ CI failed on Linux.pylatest_pip_openblas_pandas (last failure: Sep 30, 2025) ⚠️

**CI is still failing on [Linux.pylatest_pip_openblas_pandas](https://dev.azure.com/scikit-learn/scikit-learn/_build/results?buildId=80535&view=logs&j=78a0bf4f-79e5-5387-94ec-13e67d216d6e)** (Sep 30, 2025)
- test_fit_transform[98]

COMMENT:
Is the solution as simple as relaxing the thresholds, or is there an actual implementation issue with the `_fit` method?

I double-checked that default value for `max_iter` is large enough for `SparsePCA` to converge and all checked out. I was also wondering if the numerical instability could be affecting the output of `svd_flip`? I'm just throwing ideas out there :)

Labels: Bug, module:test-suite
⚠️ CI failed on Linux.pylatest_pip_openblas_pandas (last failure: Sep 30, 2025) ⚠️

**CI is still failing on [Linux.pylatest_pip_openblas_pandas](https://dev.azure.com/scikit-learn/scikit-learn/_build/results?buildId=80535&view=logs&j=78a0bf4f-79e5-5387-94ec-13e67d216d6e)** (Sep 30, 2025)
- test_fit_transform[98]

COMMENT:
Thanks for your input @j-hendricks! In this case adjusting the tolerances a bit did the trick. But sometimes addressing test failures involves a bit more work. So please don't feel discouraged to participate in conversations and you're always welcome to offer potential solutions via a comment or a pull request. :)

Labels: Bug, module:test-suite
Trees: impurity decrease calculation is buggy when there are missing values

### Describe the bug

In decision trees (both classif. and regression), the impurity decrease calculation is sometimes wrong when there are missing values in X.

This can lead to unexpectedly shallow trees when using `min_impurity_decrease` to control depth.

This was discovered during the investigations started by this issue: #32175

### Steps/Code to Reproduce

```Python
import numpy as np
from sklearn.tree import DecisionTreeRegressor

X = np.vstack([
    [0, 0, 0, 0, 1, 2, 3, 4],
    [1, 2, 1, 2, 1, 2, 1, 2]
]).swapaxes(0, 1).astype(float)
y = [0, 0, 0, 0, 1, 1, 1, 1]

n_leaves = []
for _ in range(1000):
    tree = DecisionTreeRegressor(max_depth=1, min_impurity_decrease=0.25).fit(X, y)
    # all the trees have two leaves
    assert tree.tree_.n_leaves == 2

X[X == 0] = np.nan
n_leaves_w_missing = []
for _ in range(1000):
    tree = DecisionTreeRegressor(max_depth=1, min_impurity_decrease=0.25).fit(X, y)
    n_leaves_w_missing.append(tree.tree_.n_leaves)

print(np.bincount(n_leaves_w_missing))
# prints [0 ~500 ~500]
```

The last print shows that in approx. half of the cases, the tree has only one leaf (i.e. no split).

### Expected Results

Chaning 0 by nan should have no impact on the tree construction in this example.

The tree should always have one split (and hence two leaves).

### Actual Results

In approx. half of the cases, the tree has only one leaf (i.e. no split).

### Versions

```shell
System:
    python: 3.12.11 (main, Aug 18 2025, 19:19:11) [Clang 20.1.4 ]
executable: /home/arthur/dev-perso/scikit-learn/sklearn-env/bin/python
   machine: Linux-6.14.0-29-generic-x86_64-with-glibc2.39

Python dependencies:
      sklearn: 1.8.dev0
          pip: None
   setuptools: 80.9.0
        numpy: 2.3.3
        scipy: 1.16.2
       Cython: 3.1.3
       pandas: None
   matplotlib: 3.10.6
       joblib: 1.5.2
threadpoolctl: 3.6.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
    num_threads: 16
         prefix: libscipy_openblas
       filepath: /home/arthur/dev-perso/scikit-learn/sklearn-env/lib/python3.12/site-packages/numpy.libs/libscipy_openblas64_-8fb3d286.so
        version: 0.3.30
threading_layer: pthreads
   architecture: Haswell

       user_api: blas
   internal_api: openblas
    num_threads: 16
         prefix: libscipy_openblas
       filepath: /home/arthur/dev-perso/scikit-learn/sklearn-env/lib/python3.12/site-packages/scipy.libs/libscipy_openblas-b75cc656.so
        version: 0.3.29.dev
threading_layer: pthreads
   architecture: Haswell

       user_api: openmp
   internal_api: openmp
    num_threads: 16
         prefix: libgomp
       filepath: /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0
        version: None
```

COMMENT:
Do you have thoughts on this @thomasjpfan ? I think you did a lot of work related to missing value support?! 🤞

Labels: Bug, module:tree
Trees: impurity decrease calculation is buggy when there are missing values

### Describe the bug

In decision trees (both classif. and regression), the impurity decrease calculation is sometimes wrong when there are missing values in X.

This can lead to unexpectedly shallow trees when using `min_impurity_decrease` to control depth.

This was discovered during the investigations started by this issue: #32175

### Steps/Code to Reproduce

```Python
import numpy as np
from sklearn.tree import DecisionTreeRegressor

X = np.vstack([
    [0, 0, 0, 0, 1, 2, 3, 4],
    [1, 2, 1, 2, 1, 2, 1, 2]
]).swapaxes(0, 1).astype(float)
y = [0, 0, 0, 0, 1, 1, 1, 1]

n_leaves = []
for _ in range(1000):
    tree = DecisionTreeRegressor(max_depth=1, min_impurity_decrease=0.25).fit(X, y)
    # all the trees have two leaves
    assert tree.tree_.n_leaves == 2

X[X == 0] = np.nan
n_leaves_w_missing = []
for _ in range(1000):
    tree = DecisionTreeRegressor(max_depth=1, min_impurity_decrease=0.25).fit(X, y)
    n_leaves_w_missing.append(tree.tree_.n_leaves)

print(np.bincount(n_leaves_w_missing))
# prints [0 ~500 ~500]
```

The last print shows that in approx. half of the cases, the tree has only one leaf (i.e. no split).

### Expected Results

Chaning 0 by nan should have no impact on the tree construction in this example.

The tree should always have one split (and hence two leaves).

### Actual Results

In approx. half of the cases, the tree has only one leaf (i.e. no split).

### Versions

```shell
System:
    python: 3.12.11 (main, Aug 18 2025, 19:19:11) [Clang 20.1.4 ]
executable: /home/arthur/dev-perso/scikit-learn/sklearn-env/bin/python
   machine: Linux-6.14.0-29-generic-x86_64-with-glibc2.39

Python dependencies:
      sklearn: 1.8.dev0
          pip: None
   setuptools: 80.9.0
        numpy: 2.3.3
        scipy: 1.16.2
       Cython: 3.1.3
       pandas: None
   matplotlib: 3.10.6
       joblib: 1.5.2
threadpoolctl: 3.6.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
    num_threads: 16
         prefix: libscipy_openblas
       filepath: /home/arthur/dev-perso/scikit-learn/sklearn-env/lib/python3.12/site-packages/numpy.libs/libscipy_openblas64_-8fb3d286.so
        version: 0.3.30
threading_layer: pthreads
   architecture: Haswell

       user_api: blas
   internal_api: openblas
    num_threads: 16
         prefix: libscipy_openblas
       filepath: /home/arthur/dev-perso/scikit-learn/sklearn-env/lib/python3.12/site-packages/scipy.libs/libscipy_openblas-b75cc656.so
        version: 0.3.29.dev
threading_layer: pthreads
   architecture: Haswell

       user_api: openmp
   internal_api: openmp
    num_threads: 16
         prefix: libgomp
       filepath: /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0
        version: None
```

COMMENT:
I do not think changing 0 to np.nan should impact the tree. For this specific case, the tree builder should have "split on missing".

Labels: Bug, module:tree