Skip to content

[MRG] Validate per-class RandomOverSampler shrinkage factors - #1239

Open
galafis wants to merge 2 commits into
scikit-learn-contrib:masterfrom
galafis:fix-invalid-shrinkage-factors
Open

galafis wants to merge 2 commits into
scikit-learn-contrib:masterfrom
galafis:fix-invalid-shrinkage-factors

Conversation

@galafis

@galafis galafis commented Oct 24, 2026 •

Copy link
Copy Markdown

Reference Issue

No existing issue found. This concerns validation of dictionary values, separately from the zero-shrinkage bootstrap behavior in #1228.

What does this implement/fix? Explain your changes.

RandomOverSampler(shrinkage={0: np.nan}) accepts the factor and generates NaN samples from finite input. Positive infinity is also accepted, while strings, None and complex values raise a TypeError during comparison. Scalar shrinkage already rejects these values through its parameter constraint.

Apply the same nonnegative real-number Interval constraint to each dictionary value and report the offending class in a ValueError. Document the finite-value requirement and add dense/CSR regression cases plus scalar/dictionary equivalence checks.

Before the fix, 10 new cases fail and 6 pass. With the fix, all 117 tests under imblearn/over_sampling pass on Windows with Python 3.12.14, NumPy 2.5.4, SciPy 1.17.1 and scikit-learn 1.9.1. The same 117 tests also pass with the minimum supported scikit-learn 1.4.2, NumPy 1.26.4, SciPy 1.11.4 and pandas 2.2.3. Ruff 0.4.8 and Black 23.3.0 checks pass for both changed Python files.

Any other comments?

The existing support for non-finite input with shrinkage=None is preserved. The release note includes this PR number.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant