-
Notifications
You must be signed in to change notification settings - Fork 183
[ArrayAPI] Refactor KMeans estimator to follow oneDAL estimator design pattern #2654
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
base: main
Are you sure you want to change the base?
[ArrayAPI] Refactor KMeans estimator to follow oneDAL estimator design pattern #2654
Conversation
Codecov Report❌ Patch coverage is
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
"The default value of `n_init` will change from " | ||
f"{default_n_init} to 'auto' in 1.4. Set the value of `n_init`" | ||
" explicitly to suppress the warning" | ||
f"{default_n_init} to 'auto' in 1.4. Set `n_init` explicitly " |
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.
Since we have a utility to check the sklearn version, this could be placed under an if-else, or removed altogether considering we appear to not support versions 1.1 through 1.3.
elif callable(init): | ||
cc_arr = init(X, self.n_clusters, random_state) | ||
cc_arr = np.ascontiguousarray(cc_arr, dtype=dtype) | ||
if hasattr(cc_arr, "__array_namespace__"): |
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.
Isn't the function get_namespace
supposed to be doing these checks?
Refactor KMeans estimator to follow oneDAL estimator design pattern
Depends on #2641
This PR refactors the KMeans estimator to align with the standardized design pattern used across oneDAL estimators, such as DummyEstimator outlined in #2534 . The main goal is to make the estimator consistent, maintainable, and compatible with future extensions (e.g., other algorithms or backends).
Changes Made
Reorganized KMeans and _BaseKMeans classes to follow the oneDAL estimator model pattern.
Added backend bindings using @bind_default_backend decorators:
train() → kmeans.clustering
infer() → kmeans.clustering
_is_same_clustering() → kmeans_common (no policy)
Centralized creation of the params dictionary in _get_onedal_params(...).
Ensured type dispatch and method dispatch use fptype and method respectively (e.g., by_default, lloyd_csr).
Wrapped all input/output in to_table / from_table.
Separated backend logic from estimator logic using _fit_backend() and _predict_backend().
Deferred model creation and attribute assignment to follow a minimalistic and clean init/finalization process.
Applied Sycl queue support via @supports_queue decorators for fit/predict/score.
Removed redundant or sklearn-only attributes that aren’t required by oneDAL estimators.
Preserved full feature parity (e.g., init modes, scoring, CSR support, random_state handling, etc.).
PR should start as a draft, then move to ready for review state after CI is passed and all applicable checkboxes are closed.
This approach ensures that reviewers don't spend extra time asking for regular requirements.
You can remove a checkbox as not applicable only if it doesn't relate to this PR in any way.
For example, PR with docs update doesn't require checkboxes for performance while PR with any change in actual code should have checkboxes and justify how this code change is expected to affect performance (or justification should be self-evident).
Checklist to comply with before moving PR from draft:
PR completeness and readability
Testing
Performance