-
-
Notifications
You must be signed in to change notification settings - Fork 26.5k
MAINT rename base_estimator to estimator in BaggingClassifier and BaggingRegressor #22145
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.
Hello @trujillo9616 thanks for following up!
The tests are failing because other classes depend on BaseBagging and the change affects them.
My bad, I didn't take it into account.
Do you mind reverting the changes on BaseBagging and modifying accordingly the other two? Sorry for that.
My other comment should fix the sphinx warnings in the documentation.
| Use `estimator` instead. | ||
| .. deprecated:: 1.1 |
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.
| Use `estimator` instead. | |
| .. deprecated:: 1.1 | |
| Use `estimator` instead. | |
| .. deprecated:: 1.1 |
The blank line will remove the sphinx warning... same comment in the Regressor
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.
Thanks for the review and the feedback @cmarmo ! I'll work on reverting the changes done to BaseBagging and further modifying both Bagging classes. I'll also apply your suggestion for fixing the sphinx warnings. 😁
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 one should still be fixed... :)
cmarmo
left a comment
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.
One warning is still there.
Tests are not passing, this has something to do with the inheritance... but I'm stuck.
I will try to understand, but perhaps some core dev will give some insights here...
| Use `estimator` instead. | ||
| .. deprecated:: 1.1 |
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 one should still be fixed... :)
|
Thanks for the review @cmarmo ! I'm stuck on that failing test 🙁 Still working on that and will update the PR when I have a breakthrough. The empty space was the first thing I modified, I think I undid it when reverting the changes 😅 . I will make sure to modify it on the next update! Thanks again!! |
cmarmo
left a comment
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.
Hi, I think I've found out. The common tests are failing because base_estimator changed its value in the initialization function: to avoid this the __init__ shold be
def __init__(
self,
estimator=None,
n_estimators=10,
*,
max_samples=1.0,
max_features=1.0,
bootstrap=True,
bootstrap_features=False,
oob_score=False,
warm_start=False,
n_jobs=None,
random_state=None,
verbose=0
):
super().__init__(
base_estimator=estimator,
n_estimators=n_estimators,
max_samples=max_samples,
max_features=max_features,
bootstrap=bootstrap,
bootstrap_features=bootstrap_features,
oob_score=oob_score,
warm_start=warm_start,
n_jobs=n_jobs,
random_state=random_state,
verbose=verbose
)
The issue here is that you are deprecating a positional argument which keyword does not need to be written down. The base_estimator should automatically take the value of the estimator parameter. The FutureWarning will be issued only if one explicitly write
BaggingRegressor(base_estimator=SVC())
Hope I'm not driving you on the wrong path this time....
|
|
||
| def _validate_estimator(self): | ||
| """Check the estimator and set the base_estimator_ attribute.""" | ||
| self.base_estimator = self.estimator |
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.
| self.base_estimator = self.estimator |
This line is no longer necessary
|
|
||
| def _validate_estimator(self): | ||
| """Check the estimator and set the base_estimator_ attribute.""" | ||
| self.base_estimator = self.estimator |
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.
| self.base_estimator = self.estimator |
This line is no longer necessary
|
@cmarmo You're right I am having an Assertion Error because the When running your proposed solution I am getting the following So I think we still need the What do you think? Should I ignore the deprecation cycle or keep trying to find a solution? |
Sorry if I didn't make myself clear: yes the |
|
Hello @trujillo9616 , if you are still interested in working on this, do you mind fixing conflicts and commit the version passing the tests, as we discussed earlier? It is very difficult to suggest modification without updated code. Thank you for your patience. |
|
Hi @cmarmo , I saw that this is 'Stalled'. I could help with this one if it is ok :) |
|
Please @EdAbati go on! :) |
|
I am closing this one as superseded by #23819. |
Reference Issues/PRs
See also #9104. This PR enhances some of the proposed changes in the referenced issue.
What does this implement/fix? Explain your changes.
For _bagging.py:
BaseBagging:
This enhancement renames the
base_estimatorparameter toestimatorin the BaseBagging class for improved readability and consistency. An if function was added to check if thebase_estimatorwas initialized by the user, a warning will be outputted in that case. Since the class BaseEnsemble, from which BaseBagging inherits, still uses thebase_estimatorparameter, an override for_validate_estimatorandset_paramswas done just for assigning the estimator object toself.base_estimator.BaggingClassifier and BagginRegressor:
This enhancement renames the
base_estimatorparameter toestimatorin both classes for improved readability and consistency.For test_bagging.py:
Tests in the test_bagging.py. file were modified for using the updated parameter. Two new test cases was added to check if the warning has been raised when setting the base_estimator parameter in both BaggingClassifier and BaggingRegressor.