Support more sklearn tags for testing. (#10230)
This commit is contained in:
@@ -1300,20 +1300,12 @@ def test_estimator_reg(estimator, check):
|
||||
):
|
||||
estimator.fit(X, y)
|
||||
return
|
||||
if (
|
||||
os.environ["PYTEST_CURRENT_TEST"].find("check_estimators_overwrite_params")
|
||||
!= -1
|
||||
):
|
||||
# A hack to pass the scikit-learn parameter mutation tests. XGBoost regressor
|
||||
# returns actual internal default values for parameters in `get_params`, but
|
||||
# those are set as `None` in sklearn interface to avoid duplication. So we fit
|
||||
# a dummy model and obtain the default parameters here for the mutation tests.
|
||||
from sklearn.datasets import make_regression
|
||||
|
||||
X, y = make_regression(n_samples=2, n_features=1)
|
||||
estimator.set_params(**xgb.XGBRegressor().fit(X, y).get_params())
|
||||
|
||||
check(estimator)
|
||||
elif os.environ["PYTEST_CURRENT_TEST"].find("check_regressor_multioutput") != -1:
|
||||
# sklearn requires float64
|
||||
with pytest.raises(AssertionError, match="Got float32"):
|
||||
check(estimator)
|
||||
else:
|
||||
check(estimator)
|
||||
|
||||
|
||||
def test_categorical():
|
||||
@@ -1475,3 +1467,19 @@ def test_fit_none() -> None:
|
||||
|
||||
with pytest.raises(ValueError, match="labels"):
|
||||
xgb.XGBRegressor().fit(X, None)
|
||||
|
||||
|
||||
def test_tags() -> None:
|
||||
for reg in [xgb.XGBRegressor(), xgb.XGBRFRegressor()]:
|
||||
tags = reg._more_tags()
|
||||
assert "non_deterministic" not in tags
|
||||
assert tags["multioutput"] is True
|
||||
assert tags["multioutput_only"] is False
|
||||
|
||||
for clf in [xgb.XGBClassifier()]:
|
||||
tags = clf._more_tags()
|
||||
assert "multioutput" not in tags
|
||||
assert tags["multilabel"] is True
|
||||
|
||||
tags = xgb.XGBRanker()._more_tags()
|
||||
assert "multioutput" not in tags
|
||||
|
||||
Reference in New Issue
Block a user