Skip to content

Instantly share code, notes, and snippets.

@erykml
Created February 11, 2019 22:30
Show Gist options
  • Select an option

  • Save erykml/b5aac9bd3e3491fe9eb1fbbf5d961382 to your computer and use it in GitHub Desktop.

Select an option

Save erykml/b5aac9bd3e3491fe9eb1fbbf5d961382 to your computer and use it in GitHub Desktop.
import lime
import lime.lime_tabular
explainer = lime.lime_tabular.LimeTabularExplainer(X_train.values,
mode = 'regression',
feature_names = X_train.columns,
categorical_features = [3],
categorical_names = ['CHAS'],
discretize_continuous = True)
np.random.seed(42)
exp = explainer.explain_instance(X_train.values[31], rf.predict, num_features = 5)
exp.show_in_notebook(show_all=False) #only the features used in the explanation are displayed
exp = explainer.explain_instance(X_train.values[85], rf.predict, num_features = 5)
exp.show_in_notebook(show_all=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment