Skip to content

Incompatibility with sklearn 1.8.0: _estimator_type undefined #11857

Description

@gabrielsimoes

Minimal repro:

uv run --with "xgboost==3.1.2" --with "scikit-learn==1.8.0" python -c "import xgboost as xgb; import numpy as np; clf = xgb.XGBClassifier(); clf.fit(np.array([[1,2],[3,4]]), np.array([0,1])); clf.save_model('/tmp/m.json')"

Stack trace:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import xgboost as xgb; import numpy as np; clf = xgb.XGBClassifier(); clf.fit(np.array([[1,2],[3,4]]), np.array([0,1])); clf.save_model('/tmp/m.json')
                                                                                                                             ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
  File "/Users/user/Library/Caches/uv/archive-v0/sXGU8q25SWHdmrhHwIVGT/lib/python3.13/site-packages/xgboost/sklearn.py", line 1113, in save_model
    meta["_estimator_type"] = self._get_type()
                              ~~~~~~~~~~~~~~^^
  File "/Users/user/Library/Caches/uv/archive-v0/sXGU8q25SWHdmrhHwIVGT/lib/python3.13/site-packages/xgboost/sklearn.py", line 1104, in _get_type
    raise TypeError(
    ...<2 lines>...
    )
TypeError: `_estimator_type` undefined.  Please use appropriate mixin to define estimator type.

Verified the same code works with sklearn 1.7.*

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions