You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Redundant execution of check_class_weight_balanced_linear_classifier #33154
Describe the bug and give evidence about its user-facing impact
Describe the bug and give evidence about its user-facing impact In sklearn/utils/estimator_checks.py, the function _yield_classifier_checks yields check_class_weight_balanced_linear_classifier twice for linear classifiers that support the class_weight parameter.
This bug was discovered during a manual code review of estimator_checks.py. It affects any scikit-learn user or developer who uses check_estimator (or the underlying check generators) to validate estimators.
The impact is redundant test execution. For example, when running common tests for a LogisticRegression or a custom linear classifier using the mixin, this specific check (which involves fitting the estimator and verifying class weight handling) is executed twice. This is wasteful in terms of CI/CD time and can lead to duplicated error messages or logs, making debugging more tedious.
Steps/Code to Reproduce
from sklearn.linear_model import LogisticRegression
from sklearn.utils.estimator_checks import _yield_classifier_checks
def get_name(check):
return getattr(check, "name",
getattr(check, "func", check).name)
clf = LogisticRegression()
checks = list(_yield_classifier_checks(clf))
check_names = [get_name(c) for c in checks]
duplicate_count = check_names.count(
'check_class_weight_balanced_linear_classifier'
)
print(f"Yield count: {duplicate_count}")
Expected Results
The check should be yielded exactly once. Yield count: 1
Actual Results
The check is currently yielded twice. Yield count: 2
I am interested in fixing this bug. I have already identified the root cause and implemented a fix.
Analysis of root cause: In _yield_classifier_checks, there are two consecutive if blocks that both check for isinstance(classifier, LinearClassifierMixin) and the presence of class_weight in parameters. Both blocks yield the same check.
Hi @bala-bhargav, thank you for your interest, but if you read the description carefully, you'll see that @atheendre130505 already expressed interest in fixing this, once we decide on how to proceed (see Issues tagged "Needs Triage"). See this for other more useful ways to start contributing to scikit-learn.
I agree that this looks like the same check is yielded twice.
The code was last changed in #29712 where the full snippet was added (with the duplication). I'd propose making a PR to remove the duplication and checking if all tests continue to pass without needing a change. If all those conditions are fulfilled please request a review of your PR from the author of #29712.
Activity
bala-bhargav commentedon Jan 29, 2026
@atheendre130505
can i work on this ??
AnneBeyer commentedon Jan 30, 2026
Hi @bala-bhargav, thank you for your interest, but if you read the description carefully, you'll see that @atheendre130505 already expressed interest in fixing this, once we decide on how to proceed (see Issues tagged "Needs Triage"). See this for other more useful ways to start contributing to scikit-learn.
AnneBeyer commentedon Jan 30, 2026
Thank you for pointing this out @atheendre130505!
I can confirm that there is a duplicate check in
sklearn.utils.estimator_checks.py:scikit-learn/sklearn/utils/estimator_checks.py
Lines 243 to 250 in 351280b
It was probably added by accident here and the first check can be removed.
Please still wait for a maintainer to confirm and remove the "Needs Traige" label, before submitting your PR.
betatim commentedon Feb 2, 2026
I agree that this looks like the same check is
yielded twice.The code was last changed in #29712 where the full snippet was added (with the duplication). I'd propose making a PR to remove the duplication and checking if all tests continue to pass without needing a change. If all those conditions are fulfilled please request a review of your PR from the author of #29712.