-
Notifications
You must be signed in to change notification settings - Fork 652
Add cuml.accel support for sklearn.ensemble.IsolationForest #8477
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
Open
adityaanikam
wants to merge
6
commits into
NVIDIA:main
Choose a base branch
from
adityaanikam:fea-accel-isolation-forest
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+121
−2
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1efbf48
Add cuml.accel support for sklearn.ensemble.IsolationForest
adityaanikam 0d3d714
Address review: fail loudly instead of silently on CPU conversion, tr…
adityaanikam e326371
Fix IsolationForest proxy test lint
csadorf 909c968
Apply lint fixes to ensemble overrides
csadorf c4d8376
Merge branch 'main' into fea-accel-isolation-forest
chyunsu3 f31863c
Update conversion test and docs now that #8483 landed
adityaanikam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
python/cuml/cuml_accel_tests/integration/test_isolation_forest.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import numpy as np | ||
| import pytest | ||
| from sklearn.datasets import make_blobs | ||
| from sklearn.ensemble import IsolationForest | ||
|
|
||
| CPUIsolationForest = IsolationForest._cpu_class | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def blobs_with_outliers(): | ||
| X, _ = make_blobs( | ||
| n_samples=200, | ||
| centers=1, | ||
| cluster_std=0.5, | ||
| random_state=42, | ||
| ) | ||
| rng = np.random.RandomState(42) | ||
| outliers = rng.uniform(low=-10, high=10, size=(20, X.shape[1])) | ||
| return np.vstack([X, outliers]) | ||
|
|
||
|
|
||
| def test_isolation_forest_fit_predict_agreement(blobs_with_outliers): | ||
| X = blobs_with_outliers | ||
| params = {"n_estimators": 100, "random_state": 0} | ||
|
|
||
| expected = CPUIsolationForest(**params).fit(X) | ||
| result = IsolationForest(**params).fit(X) | ||
|
|
||
| assert result._gpu is not None | ||
|
|
||
| expected_labels = expected.predict(X) | ||
| result_labels = result.predict(X) | ||
| assert set(np.unique(result_labels)) <= {-1, 1} | ||
| assert np.mean(expected_labels == result_labels) >= 0.9 | ||
|
|
||
|
|
||
| def test_isolation_forest_gpu_fit_attrs_raise_until_conversion_supported( | ||
| blobs_with_outliers, | ||
| ): | ||
| # Conversion of a fitted cuML IsolationForest back to a CPU estimator | ||
| # is not yet supported (tracked in #8420). Accessing fit attributes or | ||
| # pickling a GPU-fitted proxy must raise clearly rather than silently | ||
| # operating on an unfitted CPU estimator. | ||
| result = IsolationForest(n_estimators=50, random_state=0).fit( | ||
| blobs_with_outliers | ||
| ) | ||
| assert result._gpu is not None | ||
|
|
||
| with pytest.raises(ValueError, match="not supported"): | ||
| result.offset_ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.