Repository navigation
Description
Background
Currently, our (mostly tree-based) models supporting feature subsampling via max_features are:
DecisionTreeClassifier,DecisionTreeRegressorExtraTreeClassifier,ExtraTreeRegressorBaggingClassifier,BaggingRegressorExtraTreesClassifier,ExtraTreesRegressorGradientBoostingClassifier,GradientBoostingRegressorIsolationForestRandomForestClassifier,RandomForestRegressor
Soon, HistGradientBoostingClassifier and HistGradientBoostingRegressor will have feature subsampling, too, see #27139.
Problem Statement
max_features can be a float between 0 and 1. In this case, it means that a fraction of features is randomly selected in each split. It can also be an integer, in which case it specifies the number of features selected in each split.
This means that 1 and 1. have very different effects! See #27139 (review).
Also note that for most estimators the default is max_features=None or 1.0 meaning no subsampling. The notable exception is RandomForestClassifier and ExtraTreesClassifier with default max_features="sqrt" (which makes sense), but the corresponding regressors still use all features (so no rf but bagged trees). This was discussed in detail in #20111.
Additionally, for most estimator it means subsampling per tree split/node. For BaggingC/R models and IsolationForest it means per model/iteration.
Proposal
Accompanied with a proper deprecation strategy, we could add different arguments, one for specifying fractions, one for integer numbers.
Decision Options
A Do we want to change the current situation?
B Which names shall the new arguments have?
B.1
We could keep max_features for number of features and add only one new argument for fractions. Or we can actually add 2 new arguments and deprecate max_features completely.
B.2
Possible names for fractions, see also #27139 (comment):
colsample_bynode, same name as in XGBoost and LightGBMfeature_(sub)sample_per_splitfeature_fraction_per_split
@scikit-learn/core-devs
Activity
adrinjalali commentedon Sep 13, 2023
I personally don't see an issue with the current semantics of the parameter. So I wouldn't bother changing or adding a new parameter.
betatim commentedon Sep 20, 2023
An interesting thing to know, that I don't know how to find out, is how often someone uses
max_features=1.when they meant to usemax_features=1. This seems like the only(?) case where a user would not get what they wanted and it might be a bit tricky to track down why.If this mistake doesn't happen a lot, then maybe nothing is broken/needs fixing/changing?
The code in scikit-learn itself would be simpler if we changed this, but I'm not sure if making our lives easier is a big enough reason to change?
ogrisel commentedon Dec 4, 2023
Moving this discussion to 1.5 as I don't think we will reach a consensus for 1.4.
adrinjalali commentedon Jan 4, 2024
Should we be closing this one @lorentzenchr ?
lorentzenchr commentedon Jan 4, 2024
The answer seems to be NO.
JohnKilbride commentedon Aug 22, 2024
Given the conversation in #20111, I'm not clear why the default value of the RandomForestRegressor is set to use all features.
Using all features would make it a bagged ensemble of decision trees so the function name is actively misleading.
This seems liable to trip up beginners who may not be familiar with the details of the implementation or those coming from languages like R where the default value is something like sqrt(p) or p/3.
I don't particularly care what the subsampling fraction is set as. As show in the discussion I posted, there are many candidates and it is ultimately problem dependent. I just think that that some subsampling should be performed by default as it is basically one of the two defining features of the RandomForest algorithm.
lorentzenchr commentedon Aug 23, 2024
It is for historical reasons. I'm bothered by that situation myself.
@JohnKilbride It is best if you comment directly on #20111 and express your opinion, and then tell as many people as you can to do the same.