Support _estimator_type. (#6582)

* Use `_estimator_type`.

For more info, see: https://scikit-learn.org/stable/developers/develop.html#estimator-types

* Model trained from dask can be loaded by single node skl interface.
This commit is contained in:
Jiaming Yuan
2021-01-08 10:01:16 +08:00
committed by GitHub
parent 8747885a8b
commit f5ff90cd87
3 changed files with 81 additions and 7 deletions

View File

@@ -1099,3 +1099,26 @@ def test_boost_from_prediction_approx():
@pytest.mark.skipif(**tm.no_sklearn())
def test_boost_from_prediction_exact():
run_boost_from_prediction('exact')
def test_estimator_type():
assert xgb.XGBClassifier._estimator_type == "classifier"
assert xgb.XGBRFClassifier._estimator_type == "classifier"
assert xgb.XGBRegressor._estimator_type == "regressor"
assert xgb.XGBRFRegressor._estimator_type == "regressor"
assert xgb.XGBRanker._estimator_type == "ranker"
from sklearn.datasets import load_digits
X, y = load_digits(n_class=2, return_X_y=True)
cls = xgb.XGBClassifier(n_estimators=2).fit(X, y)
with tempfile.TemporaryDirectory() as tmpdir:
path = os.path.join(tmpdir, "cls.json")
cls.save_model(path)
reg = xgb.XGBRegressor()
with pytest.raises(TypeError):
reg.load_model(path)
cls = xgb.XGBClassifier()
cls.load_model(path) # no error