Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GBMDiscretizer fails when estimator is XGBClassifier #17

Open
kyle-clara opened this issue Jul 31, 2024 · 2 comments
Open

GBMDiscretizer fails when estimator is XGBClassifier #17

kyle-clara opened this issue Jul 31, 2024 · 2 comments

Comments

@kyle-clara
Copy link

I get the following error with xgboost==1.6.2 and scikit-gbm==0.2.1:

    109 def xgboost_trees_to_dataframe(obj):
--> 110     trees_df = obj.get_booster().trees_to_dataframe()
    112     # Rename columns
    113     trees_df = \
    114         trees_df.rename(columns={
    115             'Tree'     : 'tree_index',
   (...)
    124             'Category' : 'category' 
    125         })

AttributeError: '_XgboostWrapper' object has no attribute 'get_booster'

Reproducible example:

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
import numpy as np

iris = load_iris()
data = pd.DataFrame(
    data= np.c_[iris['data'], iris['target']],
    columns= iris['feature_names'] + ['target']
)
data.columns = data.columns.str[:-5]
data.columns = data.columns.str.replace(' ', '_')

X, y = data.iloc[:, :4], data.iloc[:, 4:]
X_train, X_test, y_train, y_test = \
    train_test_split(X, y, test_size=0.3, random_state=0)
X_cols = X.columns.tolist()

gbm_discretizer = GBMDiscretizer(XGBClassifier(verbose=-1), X_cols, one_hot=False)
gbm_discretizer.fit_transform(X_train, y_train)
@madMathematician971
Copy link

I am facing the same issue as @kyle-clara. Also, if I try to use GradientBoostingRegressor\Classifier instead of XGBoost I get a different error:

image

I believe this library was written for an earlier version of XGBoost and sklearn as I found multiple posts on StackOverflow mentioning same errors with get_booster attr missing which were resolved by downgrading xgboost.

@krzjoa Could you please specify versions of sklearn and xgboost libraries this package was written for and (preferably) update the code to work with the latest versions? Thank you

@madMathematician971
Copy link

madMathematician971 commented Oct 20, 2024

@kyle-clara My fix in #18 is verified, you can install the forked version from git until the author merges my MR

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants