-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
BUG Fixes sample weights when there are missing values in DecisionTrees #26376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG Fixes sample weights when there are missing values in DecisionTrees #26376
Conversation
@@ -2549,7 +2549,8 @@ def test_missing_values_poisson(): | |||
(datasets.make_classification, DecisionTreeClassifier), | |||
], | |||
) | |||
def test_missing_values_is_resilience(make_data, Tree): | |||
@pytest.mark.parametrize("sample_weight_train", [None, "ones"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also test the behavior when using non-uniform weights?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably, an easier test than non-uniform weight is to assign 0-weight to some specific samples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth having a separated test for checking an equivalence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you, @thomasjpfan.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
X, y = make_data(n_samples=n_samples, n_features=n_features, random_state=rng) | ||
|
||
# Create dataset with missing values | ||
X[rng.choice([False, True], size=X.shape, p=[0.9, 0.1])] = np.nan |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
neat idiom :)
Reference Issues/PRs
Follow up to #23595
What does this implement/fix? Explain your changes.
On
main
, theweighted_n_missing
was incorrectly computed. This PR fixes it. For reference the computation is exactly the same assum_total
:scikit-learn/sklearn/tree/_criterion.pyx
Lines 818 to 824 in 6be774b