Fix a few lingering sklearn compat xfails - #8166
Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughRefactors RandomForest and KNeighbors constructors to explicit sklearn-compatible keyword-only parameters and defaults. Removes deprecated RandomForest ChangesEstimator API Clarification and Sklearn Compatibility
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@python/cuml/cuml/neighbors/kneighbors_classifier.pyx`:
- Around line 154-178: Update the class/docstring for the KNeighborsClassifier
constructor to document the newly exposed parameters: p, algo_params,
metric_params, and n_jobs (even if n_jobs is ignored for compatibility). Modify
the docstring associated with __init__ (or the class-level documentation in
kneighbors_classifier.pyx) to add short descriptions for each symbol (p:
Minkowski power parameter, algo_params: algorithm-specific options,
metric_params: additional metric args, n_jobs: parallelism placeholder) and
ensure the parameter list matches the signature shown in __init__.
In `@python/cuml/cuml/neighbors/kneighbors_regressor.pyx`:
- Around line 156-180: The class docstring for KNeighborsRegressor (file:
kneighbors_regressor.pyx) is out of sync with the expanded __init__ signature;
update the class-level docstring to document the newly exposed parameters p,
algo_params, metric_params, and n_jobs: add brief descriptions (type, default,
purpose) for p (Minkowski power parameter), algo_params and metric_params (dicts
of algorithm/metric-specific options), and n_jobs (int or None, parallelism
placeholder for sklearn compatibility), ensuring the parameter list in the
docstring matches the parameters of __init__.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: a8126dd0-6d9c-4666-a24f-6323a9527d9e
📒 Files selected for processing (7)
python/cuml/cuml/ensemble/randomforest_common.pyxpython/cuml/cuml/ensemble/randomforestclassifier.pypython/cuml/cuml/ensemble/randomforestregressor.pypython/cuml/cuml/neighbors/kneighbors_classifier.pyxpython/cuml/cuml/neighbors/kneighbors_regressor.pyxpython/cuml/cuml/neighbors/nearest_neighbors.pyxpython/cuml/tests/test_sklearn_compatibility.py
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
python/cuml/cuml/neighbors/kneighbors_regressor.pyx (1)
147-148:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winFix incorrect sklearn reference in Notes section.
The docstring references
KNeighborsClassifierbut this is theKNeighborsRegressorclass. The link text and URL should reference the regressor instead.📝 Proposed fix
- For additional docs, see `scikitlearn's KNeighborsClassifier - <https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html>`_. + For additional docs, see `scikitlearn's KNeighborsRegressor + <https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsRegressor.html>`_.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@python/cuml/cuml/neighbors/kneighbors_regressor.pyx` around lines 147 - 148, Update the docstring in the KNeighborsRegressor implementation to reference the regressor docs instead of the classifier: change the link text and URL that currently point to `sklearn.neighbors.KNeighborsClassifier` to `sklearn.neighbors.KNeighborsRegressor` (e.g., update the link target and visible text in the docstring inside python/cuml/cuml/neighbors/kneighbors_regressor.pyx where the class KNeighborsRegressor is documented).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@python/cuml/cuml/neighbors/kneighbors_regressor.pyx`:
- Around line 147-148: Update the docstring in the KNeighborsRegressor
implementation to reference the regressor docs instead of the classifier: change
the link text and URL that currently point to
`sklearn.neighbors.KNeighborsClassifier` to
`sklearn.neighbors.KNeighborsRegressor` (e.g., update the link target and
visible text in the docstring inside
python/cuml/cuml/neighbors/kneighbors_regressor.pyx where the class
KNeighborsRegressor is documented).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: d1e8cb42-8461-480c-8243-aac82fbb1377
📒 Files selected for processing (2)
python/cuml/cuml/neighbors/kneighbors_classifier.pyxpython/cuml/cuml/neighbors/kneighbors_regressor.pyx
betatim
left a comment
There was a problem hiding this comment.
Thanks for this cleanup and improvement!
Have you asked who ever did the original implementation what they think about the extra time spent in fit doing the loading? I agree it makes more sense to do it then and there, but it must cost a bit of time and I assume the original author had some reason to add the complexity of making it lazy?
|
I was the original author 😉. I did that more for simplicity than anything, but now think this change makes more sense. |
|
/merge |
heh - a rare case of future you not regretting past you's choices. |
check_dont_overwrite_parametersas failing due toTSNEnot supportingn_components=1. The actual issue that test is checking for is already resolved inTSNE(no mutation in of hyperparameters).__init__for all estimators. This fixescheck_do_not_raise_errors_in_init_or_set_paramsin all remaining estimators._nvforest_modelinRandomForestClassifier/RandomForestRegressor. I think this makes sense. After afit, we should ensure the estimator is fully ready to do inference without prior additional work (which may fail). Fixescheck_dict_unchangedfor all remaining estimators.Fixes #8165.