GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — FIX return self from partial_fit of MultiOutputRegressor and BernoulliRBM by lau0708 · Pull Request #35350 · scikit-learn/scikit-learn Conversation
|
| Command | base | branch |
|---|---|---|
pytest sklearn/tests/test_multioutput.py sklearn/neural_network/tests/test_rbm.py |
96 passed | 98 passed |
pytest sklearn/tests/test_common.py -k "BernoulliRBM or MultiOutputRegressor or MultiOutputClassifier" |
— | 109 passed, 15 skipped, 2 xfailed |
ruff check + ruff format --check (0.12.2, as pinned in .pre-commit-config.yaml) |
— | clean |
Changelog fragment added under many-modules, since the fix touches both sklearn.multioutput and sklearn.neural_network; happy to split it per module or move it if you prefer.
I use scikit-learn mainly for tabular modeling. I was reading the partial_fit docstrings while working with incremental training and noticed that the Returns section promised an instance that two implementations never returned; the asymmetry with MultiOutputClassifier / BernoulliRBM.fit looked like an oversight rather than a deliberate choice.
I used AI assistance for:
Everything reported above (red/green, control assertions, test counts, lint) I ran and checked locally myself.
The issue was triaged after the earlier attempt (#35349) had already been auto-closed by the bot for being opened while the issue still carried Needs Triage; this PR is opened after triage, as the contributing guide asks.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…iRBM Both implementations documented `Returns self` but returned None, so the documented chaining idiom (`est.partial_fit(X, y).predict(X)`) raised AttributeError. MultiOutputClassifier and BernoulliRBM.fit already return the estimator, which made the two outliers hard to spot. Non-regression tests assert the return value and keep a control assertion on the sibling that already behaved correctly (scikit-learngh-35347).
|
Thank you for opening your first pull request to scikit-learn! 🎉 To help get your contribution reviewed, please make sure that:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM, but let's be a bit less verbose.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| docstrings state, instead of `None`. This restores the documented chaining | ||
| idiom, so that e.g. `est.partial_fit(X, y).predict(X)` no longer raises | ||
| `AttributeError`. Both implementations now behave like their sibling | ||
| :meth:`multioutput.MultiOutputClassifier.partial_fit` and | ||
| :meth:`neural_network.BernoulliRBM.fit`. | ||
| By :user:`lau0708`. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Too much details IMO.
| docstrings state, instead of `None`. This restores the documented chaining | |
| idiom, so that e.g. `est.partial_fit(X, y).predict(X)` no longer raises | |
| `AttributeError`. Both implementations now behave like their sibling | |
| :meth:`multioutput.MultiOutputClassifier.partial_fit` and | |
| :meth:`neural_network.BernoulliRBM.fit`. | |
| By :user:`lau0708`. | |
| docstrings state, instead of `None`. | |
| By :user:`lau0708`. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Agreed, trimmed. It is now just the two-line summary of the behaviour change — dropped the chaining / AttributeError elaboration. (f27c9ec)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| assert_array_equal(X, Xdigits) | ||
|
|
||
|
|
||
| def test_partial_fit_returns_self(): |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Maybe you could just add a small assert in an existing partial fit test instead of a new dedicated test?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Done — moved the assert rbm.partial_fit(batch) is rbm into the existing test_partial_fit loop and dropped the dedicated test. Checked that the assert still bites: removing return self gives assert None is BernoulliRBM(...). (b17ae24)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| assert not hasattr(MultiOutputRegressor(Lasso), "partial_fit") | ||
|
|
||
|
|
||
| def test_partial_fit_returns_self(): |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Maybe you could just add a small assert in an existing partial fit test instead of a new dedicated test?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Same here — the assert now sits in test_multi_target_regression_partial_fit on the second partial_fit call, and test_partial_fit_returns_self is gone. (b17ae24)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks for the review — all three points are addressed in b17ae24. Heads-up: head moved from 4416287, so the diff you looked at has shifted.
Re-checked that the assertions are load-bearing: with the two production changes reverted, they fail with |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
At least 1 approving review is required to merge this pull request.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
BUG:partial_fit returns None in MultiOutputRegressor and BernoulliRBM, contradicting its documented Returns self
There was an error while loading. Please reload this page.