-
-
Notifications
You must be signed in to change notification settings - Fork 26k
FIX IsolationForest accepts sparse matrix with float value contamination #27645
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
Conversation
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.
This works for me.
""" | ||
X, _ = make_classification(n_samples=50, n_features=4, random_state=0) | ||
X = sparse_container(X) | ||
X.sort_indices() |
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.
Out of curiosity, why do we need to sort the indices?
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.
I have no idea. I took back the minimum reproducer but it was probably failing without sorting indices.
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.
Sorting indices allows getting into a canonical representation (e.g. with no duplicates' ambiguity).
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. Thanks @glemaitre
closes #27626
This PR makes sure to convert to CSR the validated CSC matrix when contamination is a floating number. We still don't want to call
score_samples
because it will cost an additional validation, more expensive than the expectedX.asformat("csr")
.