Thanks to visit codestin.com
Credit goes to github.com

Skip to content

MNT test_tree.py::test_diabetes_underfit is flaky: it fails when changing the random seed #32192

@cakedev0

Description

@cakedev0

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

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions