diff --git a/src/treelearner/serial_tree_learner.cpp b/src/treelearner/serial_tree_learner.cpp index 22b353952eea..59a32ee1fc5b 100644 --- a/src/treelearner/serial_tree_learner.cpp +++ b/src/treelearner/serial_tree_learner.cpp @@ -702,9 +702,6 @@ void SerialTreeLearner::ComputeBestSplitForFeature( FeatureHistogram* histogram_array_, int feature_index, int real_fidx, bool is_feature_used, int num_data, const LeafSplits* leaf_splits, SplitInfo* best_split) { - if (!is_feature_used) { - return; - } SplitInfo new_split; double parent_output; if (leaf_splits->leaf_index() == 0) { @@ -730,7 +727,9 @@ void SerialTreeLearner::ComputeBestSplitForFeature( leaf_splits->leaf_index(), config_->monotone_penalty); new_split.gain *= penalty; } - if (new_split > *best_split) { + // it is needed to filter the features after the above code. + // Otherwise, the `is_splittable` in `FeatureHistogram` will be wrong, and cause some features being accidentally filtered in the later nodes. + if (new_split > *best_split && is_feature_used) { *best_split = new_split; } }