Skip to content

RandomForestRegressor doesn't accept max_samples=1.0 #20156

@UnixJunkie

Description

@UnixJunkie

Describe the bug

This example from the doc works:

from sklearn.ensemble import RandomForestRegressor
from sklearn.datasets import make_regression
X, y = make_regression(n_features=4, n_informative=2,
                       random_state=0, shuffle=False)
regr = RandomForestRegressor(max_depth=2, random_state=0)
regr.fit(X, y)
print(regr.predict([[0, 0, 0, 0]]))

Just changing one line to this:

regr = RandomForestRegressor(max_depth=2, random_state=0, max_samples=1.0)

doesn't work anymore:

ValueError: `max_samples` must be in range (0, 1) but got value 1.0

I believe max_samples=None (the default) and max_samples=1.0 should behave the same.

Steps/Code to Reproduce

see above

Versions

System:
    python: 3.8.5 (default, Jan 27 2021, 15:41:15)  [GCC 9.3.0]
executable: /usr/bin/python3
   machine: Linux-5.8.0-53-generic-x86_64-with-glibc2.29

Python dependencies:
          pip: 20.0.2
   setuptools: 45.2.0
      sklearn: 0.24.2
        numpy: 1.17.4
        scipy: 1.6.3
       Cython: None
       pandas: None
   matplotlib: 3.4.2
       joblib: 1.0.1
threadpoolctl: 2.1.0
Built with OpenMP: True

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions