-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
DecisionTreeClassifier does not support 'auto' as an option for max_features #27696
Copy link
Copy link
Closed
Closed
Copy link
Labels
Description
Describe the bug
I was using scikit-learn version 1.3.2, trying to fit a DecisionTreeClassifier to my data, and I got an error that the option 'auto' was invalid.
The documentation shows 'auto' as an available option and since it was supported in all of the previous versions, I'm guessing this is more of a bug than an error in the documentation.
Steps/Code to Reproduce
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
X, y = make_classification()
X_train, X_test, y_train, y_test = train_test_split(X, y)
DecisionTreeClassifier(max_features='auto').fit(X_train, y_train)Expected Results
No error is thrown.
Actual Results
---------------------------------------------------------------------------
InvalidParameterError Traceback (most recent call last)
Cell 2 line 5
[1] X, y = make_classification()
[3] X_train, X_test, y_train, y_test = train_test_split(X, y)
----> [5] DecisionTreeClassifier(max_features='auto').fit(X_train, y_train)
File c:\Users\\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\base.py:1145, in _fit_context.<locals>.decorator.<locals>.wrapper(estimator, *args, **kwargs)
1140 partial_fit_and_fitted = (
1141 fit_method.__name__ == "partial_fit" and _is_fitted(estimator)
1142 )
1144 if not global_skip_validation and not partial_fit_and_fitted:
-> 1145 estimator._validate_params()
1147 with config_context(
1148 skip_parameter_validation=(
1149 prefer_skip_nested_validation or global_skip_validation
1150 )
1151 ):
1152 return fit_method(estimator, *args, **kwargs)
File c:\Users\\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\base.py:638, in BaseEstimator._validate_params(self)
630 def _validate_params(self):
631 """Validate types and values of constructor parameters
632
633 The expected type and values must be defined in the `_parameter_constraints`
(...)
636 accepted constraints.
637 """
--> 638 validate_parameter_constraints(
639 self._parameter_constraints,
640 self.get_params(deep=False),
641 caller_name=self.__class__.__name__,
642 )
File c:\Users\\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\utils\_param_validation.py:96, in validate_parameter_constraints(parameter_constraints, params, caller_name)
90 else:
91 constraints_str = (
92 f"{', '.join([str(c) for c in constraints[:-1]])} or"
93 f" {constraints[-1]}"
94 )
---> 96 raise InvalidParameterError(
97 f"The {param_name!r} parameter of {caller_name} must be"
98 f" {constraints_str}. Got {param_val!r} instead."
99 )
InvalidParameterError: The 'max_features' parameter of DecisionTreeClassifier must be an int in the range [1, inf), a float in the range (0.0, 1.0], a str among {'log2', 'sqrt'} or None. Got 'auto' instead.Versions
System:
python: 3.12.0 (tags/v3.12.0:0fb18b0, Oct 2 2023, 13:03:39) [MSC v.1935 64 bit (AMD64)]
executable: c:\Users\\AppData\Local\Programs\Python\Python312\python.exe
machine: Windows-11-10.0.22621-SP0
Python dependencies:
sklearn: 1.3.2
pip: 23.3.1
setuptools: None
numpy: 1.26.1
scipy: 1.11.3
Cython: None
pandas: 2.1.1
matplotlib: 3.8.0
joblib: 1.3.2
threadpoolctl: 3.2.0
Built with OpenMP: True
threadpoolctl info:
user_api: openmp
internal_api: openmp
num_threads: 20
prefix: vcomp
filepath: C:\Users\\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn\.libs\vcomp140.dll
version: None
user_api: blas
internal_api: openblas
num_threads: 20
prefix: libopenblas
filepath: C:\Users\\AppData\Local\Programs\Python\Python312\Lib\site-packages\numpy.libs\libopenblas64__v0.3.23-293-gc2f4bdbb-gcc_10_3_0-2bde3a66a51006b2b53eb373ff767a3f.dll
version: 0.3.23.dev
threading_layer: pthreads
architecture: Prescott
user_api: blas
internal_api: openblas
num_threads: 20
prefix: libopenblas
filepath: C:\Users\\AppData\Local\Programs\Python\Python312\Lib\site-packages\scipy.libs\libopenblas_v0.3.20-571-g3dec11c6-gcc_10_3_0-c2315440d6b6cef5037bad648efc8c59.dll
version: 0.3.21.dev
threading_layer: pthreads
architecture: PrescottReactions are currently unavailable