Skip to content

Make xgboost.testing compatible with scikit-learn 1.7#11502

Merged
hcho3 merged 1 commit into
dmlc:masterfrom
hcho3:sklearn17_compat
Jun 6, 2025
Merged

Make xgboost.testing compatible with scikit-learn 1.7#11502
hcho3 merged 1 commit into
dmlc:masterfrom
hcho3:sklearn17_compat

Conversation

@hcho3

@hcho3 hcho3 commented Jun 6, 2025

Copy link
Copy Markdown
Collaborator

Starting with scikit-learn 1.7, the sklearn.utils.stats._weighted_percentile method changed its function signature. Instead of percentile parameter, it now expects percentile_rank. See scikit-learn/scikit-learn#29034. Such incompatible changes are expected, as we are using an internal method.

This should fix errors like

tree_method = 'hist', weighted = True, device = 'cpu'

    def run_adaptive(tree_method: str, weighted: bool, device: Device) -> None:
        """Test for adaptive trees."""
        rng = np.random.RandomState(1994)
        from sklearn.datasets import make_regression
        from sklearn.utils import stats
    
        n_samples = 256
        X, y = make_regression(  # pylint: disable=unbalanced-tuple-unpacking
            n_samples, 16, random_state=rng
        )
        if weighted:
            w = rng.normal(size=n_samples)
            w -= w.min()
            Xy = xgb.DMatrix(X, y, weight=w)
>           base_score = stats._weighted_percentile(  # pylint: disable=protected-access
                y, w, percentile=50
            )
E           TypeError: _weighted_percentile() got an unexpected keyword argument 'percentile'

/home/runner/.local/lib/python3.10/site-packages/xgboost/testing/updater.py:665: TypeError

(https://github.com/dmlc/xgboost/actions/runs/15484734790/job/43597489571)

@hcho3
hcho3 requested a review from trivialfis June 6, 2025 08:05
@hcho3
hcho3 merged commit 76fde56 into dmlc:master Jun 6, 2025
@hcho3
hcho3 deleted the sklearn17_compat branch June 6, 2025 18:15
trivialfis pushed a commit to trivialfis/xgboost that referenced this pull request Jul 23, 2025
@trivialfis trivialfis mentioned this pull request Jul 23, 2025
10 tasks
trivialfis added a commit that referenced this pull request Jul 23, 2025
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.

2 participants