Skip to content

FIX: Add scikit-learn >= 1.6.0 compatibility for _validate_data#41

Open
J4nvg wants to merge 1 commit into
ZhiningLiu1998:mainfrom
J4nvg:fix-sklearn-1.6-compat
Open

FIX: Add scikit-learn >= 1.6.0 compatibility for _validate_data#41
J4nvg wants to merge 1 commit into
ZhiningLiu1998:mainfrom
J4nvg:fix-sklearn-1.6-compat

Conversation

@J4nvg
Copy link
Copy Markdown

@J4nvg J4nvg commented May 1, 2026

Description

The Issue

Users installing imbalanced-ensemble alongside scikit-learn >= 1.6.0 encounter an AttributeError when calling .fit() on ensemble classifiers (e.g., SelfPacedEnsembleClassifier).

AttributeError: 'SelfPacedEnsembleClassifier' object has no attribute '_validate_data'

This happens because scikit-learn version 1.6.0 removed the private _validate_data method from the BaseEstimator class and moved it to a public standalone utility function (sklearn.utils.validation.validate_data).

The Solution

This PR introduces a backward-compatible bridge in imbens/ensemble/base.py to handle the version difference dynamically without breaking older setups.

  • Added a try/except block to safely import validate_data from sklearn.utils.validation if it exists.
  • Overrode _validate_data in BaseImbalancedEnsemble to act as a routing method:
    • If scikit-learn >= 1.6.0, it passes the arguments to the new utility function.
    • If scikit-learn < 1.6.0, it falls back to super()._validate_data().

Testing

  • Successfully built locally.
  • Verified that the AttributeError is resolved when running with scikit-learn==1.6.0.
  • Ran the local pytest suite. All core ensemble tests pass successfully, confirming that the fallback preserves behavior for existing logic.

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