The Wayback Machine - https://web.archive.org/web/20210914235352/https://github.com/scikit-learn/scikit-learn/pull/19310
Skip to content
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

[MRG] ENH Consistent loss name for squared error #19310

Merged
merged 28 commits into from Mar 19, 2021

Conversation

@lorentzenchr
Copy link
Member

@lorentzenchr lorentzenchr commented Jan 31, 2021

Reference Issues/PRs

Partially solves #18248.

What does this implement/fix? Explain your changes.

This PR renames all variations of squared error to "squared_error".

Questions

One open question is: What to do with the export of Tree in sklearn/tree/_export.py? Replace "mse" with "squared_error" or keep the name "mse"?
Currently, the text for criterion="squared_error" is set to "mse".

@lorentzenchr lorentzenchr changed the title [WIP] Consistent loss name for squared error [MRG] ENH Consistent loss name for squared error Feb 1, 2021
Copy link
Member

@thomasjpfan thomasjpfan left a comment

I am mostly on board with this change. In the short term it would be a bit painful for users and educational material, but I am all for being more consistent.

doc/modules/ensemble.rst Outdated Show resolved Hide resolved
sklearn/ensemble/_gb.py Outdated Show resolved Hide resolved
sklearn/tree/_export.py Outdated Show resolved Hide resolved
Copy link
Member

@rth rth left a comment

A few minor comments otherwise LGTM. Thanks!

doc/modules/ensemble.rst Outdated Show resolved Hide resolved
examples/ensemble/plot_gradient_boosting_quantile.py Outdated Show resolved Hide resolved
examples/ensemble/plot_gradient_boosting_quantile.py Outdated Show resolved Hide resolved
sklearn/linear_model/_ransac.py Outdated Show resolved Hide resolved
@lorentzenchr
Copy link
Member Author

@lorentzenchr lorentzenchr commented Feb 27, 2021

How to write a whatsnew entry for this?

  1. Several entries per module affected.
  2. One meta entry for all changes together.

@thomasjpfan
Copy link
Member

@thomasjpfan thomasjpfan commented Feb 27, 2021

I would prefer one entry that contains a list where each item maps from the old name to the new name for each estimator. I suspect we would need to update this list as we change other names. This would be similar to what we did for gradient boosting when there were multiple features:

Screen Shot 2021-02-27 at 6 29 00 PM

@rth
rth approved these changes Mar 2, 2021
Copy link
Member

@rth rth left a comment

Once a changelog is added. Also +1 for a single entry. Thanks!

@rth
Copy link
Member

@rth rth commented Mar 2, 2021

Also there are CI failure and merge conflicts currently...

@lorentzenchr lorentzenchr added this to the 1.0 milestone Mar 9, 2021
@rth rth requested a review from thomasjpfan Mar 9, 2021
@lorentzenchr
Copy link
Member Author

@lorentzenchr lorentzenchr commented Mar 12, 2021

@thomasjpfan I placed an entry in the what's new directly below Changelog before the sections of submodules as this change concerns many different submodules.

Copy link
Member

@thomasjpfan thomasjpfan left a comment

One comment regarding BaseEnsemble

if getattr(estimator, "criterion", None) == "mse":
estimator.set_params(criterion="squared_error")
Comment on lines 157 to 158

This comment has been minimized.

@thomasjpfan

thomasjpfan Mar 13, 2021
Member

Estimators such as BaggingClassifier accepts a base_estimator parameter. This means that third-party estimators passed as base_estimator could have a "criterion" parameter that does not support "squared_error". Currently, I see two ways around this:

  1. The hacky workaround would be to detect the classes we made the name change to and only make this change for those classes.

  2. A cleaner solution would be to remove criterion from self.estimator_params and have a "additional_estimator_params" kwarg in _make_estimator. This way the caller can set a self.criterion_ and pass it into _make_estimator. This would be...more code tho and maybe a little over-engineered for something we are going to remove anyways.

This comment has been minimized.

@lorentzenchr

lorentzenchr Mar 14, 2021
Author Member

As we're going to remove this piece of code anyway, I'd go for solution 1. Deprecation for criterion="mse" was made for:

  • ExtraTreesRegressor
  • RandomForestRegressor
  • DecisionTreeRegressor
  • ExtraTreeRegressor

This comment has been minimized.

@lorentzenchr

lorentzenchr Mar 14, 2021
Author Member

The problem is that RandomForestRegressor inherits from BaseEnsemble. Suggestions?

This comment has been minimized.

@ogrisel

ogrisel Mar 15, 2021
Member

+1 for the first solution ("detect the classes we made the name change to and only make this change for those classes"). It feels like that a saner and more predictable way to handle deprecation.

But actually, I don't understand why we even need to do this. Why not just let the warning passthrough if the user has code with a base estimator explicitly constructed with criterion="mse"?

If they just use the default, they should not get any warning, no?

This comment has been minimized.

@thomasjpfan

thomasjpfan Mar 15, 2021
Member

When a user sets RandomForestRegressor(criterion='mse'), this PR currently raises a warning in RandomForestRegressor.fit. Later in _make_estimator, criterion would be passed down to base estimators through self.estimator_params. This would raise warnings again when the base estimator fit methods are called.

The problem is that RandomForestRegressor inherits from BaseEnsemble. Suggestions?

I think we only need to re-set criterion for RandomForestRegressor and ExtraTreesRegressor, where base_estimator can not be passed in and criterion can be passed in. So for maintainability, we only need to detect for ExtraTreeRegressor and DecisionTreeRegressor in _make_estimator.

This comment has been minimized.

@thomasjpfan

thomasjpfan Mar 15, 2021
Member

Another "more correct" OOP solution would be to remove "criterion" from estimator_params in RandomForestRegressor and ExtraTreesRegressor, and when we warn about criterion in BaseForest.fit, we set criterion correctly:

self._validate_estimator()
# TODO: Remove in v1.2
if isinstance(self, (RandomForestRegressor, ExtraTreesRegressor)) self.criterion == "mse":
    warn(...)
	self.base_estimator_.criterion = "squared_error"

This comment has been minimized.

@lorentzenchr

lorentzenchr Mar 15, 2021
Author Member

Can you check again with 7d220b8?

Copy link
Member

@ogrisel ogrisel left a comment

Just a few small comments but otherwise LGTM!

doc/whats_new/v1.0.rst Outdated Show resolved Hide resolved
if getattr(estimator, "criterion", None) == "mse":
estimator.set_params(criterion="squared_error")

This comment has been minimized.

@ogrisel

ogrisel Mar 15, 2021
Member

+1 for the first solution ("detect the classes we made the name change to and only make this change for those classes"). It feels like that a saner and more predictable way to handle deprecation.

But actually, I don't understand why we even need to do this. Why not just let the warning passthrough if the user has code with a base estimator explicitly constructed with criterion="mse"?

If they just use the default, they should not get any warning, no?

@ogrisel
Copy link
Member

@ogrisel ogrisel commented Mar 19, 2021

@thomasjpfan's remaining comment has been addressed, let's merge :)

@ogrisel ogrisel merged commit b9d6db8 into scikit-learn:main Mar 19, 2021
26 checks passed
26 checks passed
@github-actions
check
Details
@github-actions
triage
Details
@github-actions
Check build trigger
Details
@github-actions
Build wheel for cp${{ matrix.python }}-${{ matrix.platform_id }}-${{ matrix.manylinux_image }}
Details
@github-actions
Source distribution
Details
@github-actions
Upload to Anaconda
Details
@lgtm-com
LGTM analysis: C/C++ No code changes detected
Details
@lgtm-com
LGTM analysis: JavaScript No code changes detected
Details
@lgtm-com
LGTM analysis: Python No new or fixed alerts
Details
ci/circleci: deploy Your tests passed on CircleCI!
Details
ci/circleci: doc Your tests passed on CircleCI!
Details
@circleci-artifacts-redirector
ci/circleci: doc artifact Link to 0/doc/_changed.html
Details
ci/circleci: doc-min-dependencies Your tests passed on CircleCI!
Details
ci/circleci: lint Your tests passed on CircleCI!
Details
@azure-pipelines
scikit-learn.scikit-learn Build #20210315.19 succeeded
Details
@azure-pipelines
scikit-learn.scikit-learn (Get Git Commit) Get Git Commit succeeded
Details
@azure-pipelines
scikit-learn.scikit-learn (Linting) Linting succeeded
Details
@azure-pipelines
scikit-learn.scikit-learn (Linux py36_conda_openblas) Linux py36_conda_openblas succeeded
Details
@azure-pipelines
scikit-learn.scikit-learn (Linux py36_ubuntu_atlas) Linux py36_ubuntu_atlas succeeded
Details
@azure-pipelines
scikit-learn.scikit-learn (Linux pylatest_pip_openblas_pandas) Linux pylatest_pip_openblas_pandas succeeded
Details
@azure-pipelines
scikit-learn.scikit-learn (Linux32 py36_ubuntu_atlas_32bit) Linux32 py36_ubuntu_atlas_32bit succeeded
Details
@azure-pipelines
scikit-learn.scikit-learn (Linux_Runs pylatest_conda_mkl) Linux_Runs pylatest_conda_mkl succeeded
Details
@azure-pipelines
scikit-learn.scikit-learn (Windows py36_pip_openblas_32bit) Windows py36_pip_openblas_32bit succeeded
Details
@azure-pipelines
scikit-learn.scikit-learn (Windows py37_conda_mkl) Windows py37_conda_mkl succeeded
Details
@azure-pipelines
scikit-learn.scikit-learn (macOS pylatest_conda_forge_mkl) macOS pylatest_conda_forge_mkl succeeded
Details
@azure-pipelines
scikit-learn.scikit-learn (macOS pylatest_conda_mkl_no_openmp) macOS pylatest_conda_mkl_no_openmp succeeded
Details
@ogrisel
Copy link
Member

@ogrisel ogrisel commented Mar 19, 2021

Thanks @lorentzenchr!

@lorentzenchr lorentzenchr deleted the lorentzenchr:consistent_squared_error branch Mar 19, 2021
@glemaitre glemaitre mentioned this pull request Apr 22, 2021
10 of 12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants