How to use the lime.lime_tabular.LimeTabularExplainer function in lime

To help you get started, we’ve selected a few lime examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GaelVaroquaux / interpreting_ml_tuto / src / 02_why / 04_black_box_interpretation.py View on Github external
regressor = ensemble.RandomForestRegressor()
regressor.fit(X_train, y_train)

##########################################################
# Inspect predictions for a few houses
#
# For this, separate out the categorical features:
import numpy as np
categorical_features = [i for i, col in enumerate(boston.data.T)
                        if np.unique(col).size < 10]

##########################################################
# Now use a lime explainer for tabular data
from lime.lime_tabular import LimeTabularExplainer
explainer = LimeTabularExplainer(X_train,
    feature_names=boston.feature_names,
    class_names=['price'],
    categorical_features=categorical_features,
    mode='regression')

# Now explain a prediction
exp = explainer.explain_instance(X_test[25], regressor.predict,
        num_features=10)

exp.as_pyplot_figure()
from matplotlib import pyplot as plt
plt.tight_layout()
##########################################################
print(exp.as_list())

##########################################################
github interpretml / interpret / python / interpret-core / interpret / blackbox / lime.py View on Github external
self.predict_fn = unify_predict_fn(predict_fn, self.data)
        self.n_jobs = n_jobs

        if sampler is not None:  # pragma: no cover
            warnings.warn("Sampler interface not currently supported.")

        self.sampler = sampler
        self.explain_kwargs = explain_kwargs

        self.kwargs = kwargs
        final_kwargs = {"mode": "regression"}
        if self.feature_names:
            final_kwargs["feature_names"] = self.feature_names
        final_kwargs.update(self.kwargs)

        self.lime = LimeTabularExplainer(self.data, **final_kwargs)