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 Predictions not working #214

Open
xnmp opened this issue Jun 14, 2017 · 3 comments
Open

Explain Predictions not working #214

xnmp opened this issue Jun 14, 2017 · 3 comments

Comments

@xnmp
Copy link

xnmp commented Jun 14, 2017

So I have a model called gbm. gbm.predict_proba(X) works, and explain_weights(gbm) works. But when I try to write

explain_prediction(gbm, X.iloc[1])

I get ValueError: DataFrame.dtypes for data must be int, float or bool. Did not expect that data types in fields (every field).

If I instead write

explain_prediction(gbm, X.iloc[1].values)

I get an answer, but all the features are label x1,x2,x3, etc.

Any idea what's going on?

@lopuhin
Copy link
Contributor

lopuhin commented Jun 15, 2017

hi @xnmp ! Can you please give the original traceback you get? I tried to reproduce the issue, but didn't get an error - probably you are doing something differently:

import pandas as pd
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.datasets import load_iris

data = load_iris()
data.keys()

X = pd.DataFrame(data['data'], columns=data['feature_names'])

gbm = GradientBoostingClassifier()
gbm.fit(X, data['target'])

eli5.show_weights(gbm)
eli5.show_prediction(gbm, X.iloc[1])

image

@lextoumbourou
Copy link

I'm having the same issue with a LightGBM. I found a simple workaround, which is to specify the columns using the feature_names arg:

explain_prediction(gbm, X.iloc[1].values, feature_names=list(X.columns))

@agnesvanbelle
Copy link

I had the same problem and above did not solve it for me. What worked for me was using X.iloc[[1]] instead of X.iloc[1]. The latter form automatically converts a row to a series, which converts the datatypes in the row to "object" type if they differ.

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

No branches or pull requests

5 participants