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

This is a bug on xgboost. #392

Open
Columbine21 opened this issue Oct 21, 2020 · 2 comments
Open

This is a bug on xgboost. #392

Columbine21 opened this issue Oct 21, 2020 · 2 comments

Comments

@Columbine21
Copy link

Description: XGBClassifier explainer failed when n_estimators=1.(extreme situation)
E.g.
model_t = XGBClassifier(random_state=1111, max_depth=4, n_estimators=1)

show_prediction(model, test_input[tougue_correct_q[0]]) will failed to run.

The error message is as follows:
截屏2020-10-21 上午9 18 32

@pjgao
Copy link

pjgao commented Mar 9, 2021

same errors, the problem lies in :

def _prediction_feature_weights(booster, dmatrix, n_targets,
                                feature_names, xgb_feature_names):
    """ For each target, return score and numpy array with feature weights
    on this prediction, following an idea from
    http://blog.datadive.net/interpreting-random-forests/
    """
    # XGBClassifier does not have pred_leaf argument, so use booster
    leaf_ids, = booster.predict(dmatrix, pred_leaf=True)

booster.predict(dmatrix, pred_leaf=True) will return a 1-d array when only one tree in xgboost.
this may be modified to:

def _prediction_feature_weights(booster, dmatrix, n_targets,
                                feature_names, xgb_feature_names):
    """ For each target, return score and numpy array with feature weights
    on this prediction, following an idea from
    http://blog.datadive.net/interpreting-random-forests/
    """
    # XGBClassifier does not have pred_leaf argument, so use booster
    leaf_ids, = booster.predict(dmatrix, pred_leaf=True).reshape(1,-1)

@pjgao
Copy link

pjgao commented Mar 9, 2021

Now the question is: Is dmatrix only contains one sample ?

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