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

explain_prediction_lightgbm doesnt work for microsoft lightgbm #415

Open
CynthiaLong opened this issue Dec 12, 2021 · 1 comment
Open

explain_prediction_lightgbm doesnt work for microsoft lightgbm #415

CynthiaLong opened this issue Dec 12, 2021 · 1 comment

Comments

@CynthiaLong
Copy link

When I call the function explain_prediction_lightgbm on my lightgbm booster model,
eli5.lightgbm.explain_prediction_lightgbm(model1, doc=example, feature_names=list(example.index))
where model1 is <class 'lightgbm.basic.Booster'> ,
example is <class 'pandas.core.series.Series'>,
and list(example.index) is a list of string of the data feature names

I encounter the following error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-27-199da8311346> in <module>()
----> 1 eli5.lightgbm.explain_prediction_lightgbm(model1, doc=example, feature_names=list(example.index))

/opt/xxx/software/anaconda3/lib/python3.6/site-packages/eli5/lightgbm.py in explain_prediction_lightgbm(lgb, doc, vec, top, top_targets, target_names, targets, feature_names, feature_re, feature_filter, vectorized)
    109     """
    110 
--> 111     vec, feature_names = handle_vec(lgb, doc, vec, vectorized, feature_names)
    112     if feature_names.bias_name is None:
    113         # LightGBM estimators do not have an intercept, but here we interpret

/opt/xxx/software/anaconda3/lib/python3.6/site-packages/eli5/sklearn/utils.py in handle_vec(clf, doc, vec, vectorized, feature_names, num_features)
    260         vec, feature_names, coef_scale=None, with_coef_scale=False)
    261     feature_names = get_feature_names(
--> 262         clf, vec, feature_names=feature_names, num_features=num_features)
    263     return vec, feature_names
    264 

/opt/xxx/software/anaconda3/lib/python3.6/site-packages/eli5/sklearn/utils.py in get_feature_names(clf, vec, bias_name, feature_names, num_features, estimator_feature_names)
     93             return FeatureNames(estimator_feature_names, bias_name=bias_name)
     94 
---> 95     num_features = num_features or get_num_features(clf)
     96     if isinstance(feature_names, FeatureNames):
     97         if feature_names.n_features != num_features:

/opt/xxx/software/anaconda3/lib/python3.6/site-packages/eli5/sklearn/utils.py in get_num_features(estimator)
    211     else:
    212         raise ValueError("Can't figure out feature vector size for %s" %
--> 213                          estimator)
    214 
    215 

ValueError: Can't figure out feature vector size for <lightgbm.basic.Booster object at 0x7fa5115826a0>

@az0
Copy link

az0 commented Nov 16, 2022

FWIW, it works for me

eli5.show_prediction(clf,this_row, feature_names=feature_names, show_feature_values=True, top=20)

clf=<class 'lightgbm.basic.Booster'>
this_row=<class 'pandas.core.series.Series'>
feature_names=<class 'list'>

LightGBM version: 3.3.3
eli5 version: 0.13.0

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