-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
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
ENH add new common test: test_negative_sample_weight_support
and allow_negative_sample_weight
tag
#21132
Conversation
…ase error was wrong and some tag changes where it was needed
…e it fails tests and previously it wasnt there.
… it wasnt there before.
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. |
Related: #15657. |
Good point, Maybe the default |
Closing as there hasn't been further activity from the OP. |
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 doesntsupports negative
sample_weight
. In this case there is a check for the negative case. This far the following estimatorschecked for negative weights:
LinearRegression
,AdaBoostClassifier
,AdaBoostRegressor
, andKDEDensity
.Some estimators raised misleading error in the negative weight case:
BayesianRidge
,KernelRidge
,Ridge
,RidgeClassifier
,ElasticNetCV
andLassoCV
. 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
andMultiOutputEstimator
.A common test is added:
test_negative_sample_weight_support
. This checks all estimators in_tested_estimators()
where the estimator hassample_weight
parameter infit
. 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 thefit
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 usessample_weight
infit
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.