Skip to content

Getting error while calling LimeTabular with ColumnTransformation  #322

Open

Description

@ritathakor

Hi

I would like to use LIME interpretation for the dataset, where i have done preprocessing like OneHotCoding, Imputer, Calculating new feature using ColumnTransformation. I found the below sample code provided for TabularExplainer (interpret-community). Here, the interpretation is provided on the raw feature based on transformation been passed.

When i have tried doing the same using LimeTabular i get the error, "Specifying the columns using strings is only supported for pandas DataFrames"

How i can achieve the interpretation of raw feature after such preprocessing is done?

`from sklearn.compose import ColumnTransformer

pipeLine1 = Pipeline(steps=[
('imputer', SimpleImputer(strategy='median')),
('scaler', StandardScaler())
])
pipeLine2 = Pipeline(steps=[
("imputer", SimpleImputer(strategy='constant', fill_value='missing')),
("encoder", OneHotEncoder(sparse=False))])

transformations = ColumnTransformer([
("age_fare_1", pipeLine1 , ["age", "fare"])
,("age_fare_2", many_to_one_transformer, ["age", "fare"])
, ("age_fare_3", many_to_many_transformer, ["age", "fare"])
, ("embarked", pipeLine2, ["embarked"])
, ("sex_pclass", OneHotEncoder(sparse=False), ["sex", "pclass"])
])`

`clf = Pipeline(steps=[('preprocessor', transformations),
('classifier', LogisticRegression(solver='lbfgs'))])
model = clf.fit(x_train, y_train)

lime = LimeTabular(predict_fn=model.predict_proba, data=x_train)
lime_local = lime.explain_local(x_test[:5], y_test[:5])

show(lime_local)`

Please suggest.

Thanks
Rita

Activity

  1. koschmid commented on Apr 26, 2022

    @koschmid

    I ran into the same problem.

    Would be nice if anybody has an idea about it.

    Regards
    Konstantin

  2. paulbkoch commented on Feb 13, 2023

    @paulbkoch
    Collaborator

    This isn't in an area of the code that I am familiar with (yet), but if you're still tracking this issue @ritathakor or @koschmid can you tell me what type x_train is? Does LimeTabular still fail if x_train is a Pandas dataframe?

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions