|
8 | 8 |
|
9 | 9 | import xgboost as xgb
|
10 | 10 | from xgboost import testing as tm
|
| 11 | +from xgboost.core import _parse_version |
11 | 12 | from xgboost.testing.params import (
|
12 | 13 | cat_parameter_strategy,
|
13 | 14 | exact_parameter_strategy,
|
@@ -375,16 +376,25 @@ def test_categorical_missing(self, rows: int, cols: int, cats: int) -> None:
|
375 | 376 |
|
376 | 377 | def run_adaptive(self, tree_method, weighted) -> None:
|
377 | 378 | rng = np.random.RandomState(1994)
|
| 379 | + from sklearn import __version__ as sklearn_version |
378 | 380 | from sklearn.datasets import make_regression
|
379 | 381 | from sklearn.utils import stats
|
380 | 382 |
|
381 | 383 | n_samples = 256
|
382 | 384 | X, y = make_regression(n_samples, 16, random_state=rng)
|
| 385 | + (sk_major, sk_minor, _), _ = _parse_version(sklearn_version) |
| 386 | + if sk_major > 1 or sk_minor >= 7: |
| 387 | + kwargs = {"percentile_rank": 50} |
| 388 | + else: |
| 389 | + kwargs = {"percentile": 50} |
| 390 | + |
383 | 391 | if weighted:
|
384 | 392 | w = rng.normal(size=n_samples)
|
385 | 393 | w -= w.min()
|
386 | 394 | Xy = xgb.DMatrix(X, y, weight=w)
|
387 |
| - base_score = stats._weighted_percentile(y, w, percentile=50) |
| 395 | + base_score = stats._weighted_percentile( # pylint: disable=protected-access |
| 396 | + y, w, **kwargs |
| 397 | + ) |
388 | 398 | else:
|
389 | 399 | Xy = xgb.DMatrix(X, y)
|
390 | 400 | base_score = np.median(y)
|
|
0 commit comments