Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ENH add new common test: test_negative_sample_weight_support and allow_negative_sample_weight tag #21132

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

simonandras
Copy link
Contributor

@simonandras simonandras commented Sep 23, 2021

Reference Issues/PRs

Fixes #15531.

What does this implement/fix? Explain your changes.

A new tag is added: allow_negative_sample_weight. By default it is True, and it is changed to False if the estimator doesnt
supports negative sample_weight. In this case there is a check for the negative case. This far the following estimators
checked for negative weights: LinearRegression, AdaBoostClassifier, AdaBoostRegressor, and KDEDensity.


Some estimators raised misleading error in the negative weight case: BayesianRidge, KernelRidge, Ridge, RidgeClassifier, ElasticNetCV and LassoCV. These are updated. Some estimators which uses another estimator copies its allow_negative_sample_weight tag. It is needed because those estimators fit method will be used, so they have to handle sample_weights the same way: RANSACRegressor, StackingRegressor, StackingClassifier, VotingRegressor, VotingClassifier and MultiOutputEstimator.


A common test is added: test_negative_sample_weight_support. This checks all estimators in _tested_estimators() where the estimator has sample_weight parameter in fit. If the estimator has False tag then the appropriate error is expected, else no error.


A helper function is added: _create_data_for_fit. This function is needed to run the fit method in the test.

Any other comments?

Now every estimator in _tested_estimators() is explicitly tested by using neagative weights in fit and check for result. There is no estimator which uses sample_weight in fit and it is not listed in _tested_estimators(). The changes are backward compatible, because only those cases were updated where the negative weight case raised another error so far.

@ogrisel
Copy link
Member

ogrisel commented Dec 9, 2021

I wonder if we should assume that negative weight work by default. I don't really see a valid use case for negative weights and don't want to enforce complexity of handling this edge case if it's not any practical use.

@ogrisel
Copy link
Member

ogrisel commented Dec 9, 2021

Related: #15657.

@cmarmo cmarmo added module:test-suite everything related to our tests Needs Decision Requires decision labels Jan 5, 2022
@cmarmo
Copy link
Contributor

cmarmo commented Aug 6, 2022

Also related #12464 and #3774.

@haiatn
Copy link
Contributor

haiatn commented Oct 5, 2022

I wonder if we should assume that negative weight work by default. I don't really see a valid use case for negative weights and don't want to enforce complexity of handling this edge case if it's not any practical use.

Good point, Maybe the default allow_negative_sample_weight tag should be false

@adrinjalali
Copy link
Member

Closing as there hasn't been further activity from the OP.

@adrinjalali adrinjalali closed this Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module:test-suite everything related to our tests Needs Decision Requires decision
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enforce positive sample_weight
5 participants