Skip to content

BUG: XGBoost Classes unusable with scikit-activeml 0.5.2 and Python 3.12 #481

Closed

Description

@perceptualJonathan

Describe the issue:

Previously with scikit-activeml 0.4.1 and Python 3.8, xgboost classes could be used with scikit-activeml. However, after updating to version 0.5.2 and Python 3.12, attempting to use an xgboost class results in a parsing error. This error is not a fatal syntax error that would kill the program when instantiating the SklearnClassifier object. Instead, when attempting to use the object, call clf.fit, etc., then the error is pitched.

Reproduce the bug via a code example:

import xgboost as xgb
from skactiveml.classifier import SklearnClassifier
xgbc = xgb.XGBClassifier()
clf = SklearnClassifier(xgbc, classes=[0, 1])
clf

Error message:

Error in generated code:
def fit(self, X: Any, y: Any, *, sample_weight: Optional[Any] = None, base_margin: Optional[Any] = None, eval_set: Optional[Sequence[Tuple[Any, Any]]] = None, verbose: Union[bool, int, NoneType] = True, xgb_model: Union[xgboost.core.Booster, str, xgboost.sklearn.XGBModel, NoneType] = None, sample_weight_eval_set: Optional[Sequence[Any]] = None, base_margin_eval_set: Optional[Sequence[Any]] = None, feature_weights: Optional[Any] = None) -> 'XGBClassifier):
    pass

  File <makefun-gen-4>:1
    def fit(self, X: Any, y: Any, *, sample_weight: Optional[Any] = None, base_margin: Optional[Any] = None, eval_set: Optional[Sequence[Tuple[Any, Any]]] = None, verbose: Union[bool, int, NoneType] = True, xgb_model: Union[xgboost.core.Booster, str, xgboost.sklearn.XGBModel, NoneType] = None, sample_weight_eval_set: Optional[Sequence[Any]] = None, base_margin_eval_set: Optional[Sequence[Any]] = None, feature_weights: Optional[Any] = None) -> 'XGBClassifier):
                                                                                                                                                                                                                                                                                                                                                                                                                                                               ^
SyntaxError: unterminated string literal (detected at line 1)
Error in generated code:
def fit(self, X: Any, y: Any, *, sample_weight: Optional[Any] = None, base_margin: Optional[Any] = None, eval_set: Optional[Sequence[Tuple[Any, Any]]] = None, verbose: Union[bool, int, NoneType] = True, xgb_model: Union[xgboost.core.Booster, str, xgboost.sklearn.XGBModel, NoneType] = None, sample_weight_eval_set: Optional[Sequence[Any]] = None, base_margin_eval_set: Optional[Sequence[Any]] = None, feature_weights: Optional[Any] = None) -> 'XGBClassifier):
    pass

  File <makefun-gen-5>:1
    def fit(self, X: Any, y: Any, *, sample_weight: Optional[Any] = None, base_margin: Optional[Any] = None, eval_set: Optional[Sequence[Tuple[Any, Any]]] = None, verbose: Union[bool, int, NoneType] = True, xgb_model: Union[xgboost.core.Booster, str, xgboost.sklearn.XGBModel, NoneType] = None, sample_weight_eval_set: Optional[Sequence[Any]] = None, base_margin_eval_set: Optional[Sequence[Any]] = None, feature_weights: Optional[Any] = None) -> 'XGBClassifier):
                                                                                                                                                                                                                                                                                                                                                                                                                                                               ^
SyntaxError: unterminated string literal (detected at line 1)

Context for the issue:

No response

Activity

  1. changed the title [-]BUG: XGBoost Classes unusable with scikit-activeml 0.5.2[/-] [+]BUG: XGBoost Classes unusable with scikit-activeml 0.5.2 and Python 3.12[/+] on Feb 5, 2025
  2. tpham93 commented on Feb 6, 2025

    @tpham93
    Contributor

    Hi @perceptualJonathan

    Thanks for bringing this issue to our awareness! We have changed the way how the signatures for wrapped functions are copied now, so type hints and references to non-native default values and types should work correctly now (see #482). The upcoming release should include this change.

    If you want to try out the changes before the release, feel free to check out the following branch #481 branch.
    To install it locally, change the version in setup.py and use pip -e <path to repo>.

    Here is the output for the #481 branch:

    from skactiveml.utils import MISSING_LABEL
    from skactiveml.classifier import SklearnClassifier
    from sklearn.datasets import make_classification
    import xgboost as xgb
    
    xgbc = xgb.XGBClassifier()
    
    clf = SklearnClassifier(xgbc, classes=[0, 1], missing_label=MISSING_LABEL)
    X, y = make_classification(random_state=0)
    y = y.astype(float)
    y_train = y.copy()
    y_train[15:] = MISSING_LABEL
    
    clf.fit(X,y_train)
    print(clf.score(X, y))
    clf.fit(X,y)
    print(clf.score(X, y))

    Output:

    0.88
    1.0
    
  3. perceptualJonathan commented on Feb 6, 2025

    @perceptualJonathan
    Author

    Super. Thanks.

  4. mherde commented on Apr 9, 2025

    @mherde
    Contributor

    Hi @perceptualJonathan

    We've just released skactiveml 0.6.0, where xgboost is supported according to the above example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions