Skip to content

Commit

Permalink
added sampling around instance option for continuous features in lime…
Browse files Browse the repository at this point in the history
… tabular.
  • Loading branch information
marcotcr committed May 25, 2018
1 parent 6808f82 commit 6946cbe
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lime/lime_tabular.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def __init__(self,
feature_selection='auto',
discretize_continuous=True,
discretizer='quartile',
sample_around_instance=False,
random_state=None):
"""Init function.
Expand Down Expand Up @@ -140,13 +141,18 @@ def __init__(self,
discretizer: only matters if discretize_continuous is True. Options
are 'quartile', 'decile', 'entropy' or a BaseDiscretizer
instance.
sample_around_instance: if True, will sample continuous features
in perturbed samples from a normal centered at the instance
being explained. Otherwise, the normal is centered on the mean
of the feature data.
random_state: an integer or numpy.RandomState that will be used to
generate random numbers. If None, the random state will be
initialized using the internal numpy seed.
"""
self.random_state = check_random_state(random_state)
self.mode = mode
self.categorical_names = categorical_names or {}
self.sample_around_instance = sample_around_instance

if categorical_features is None:
categorical_features = []
Expand Down Expand Up @@ -402,7 +408,10 @@ def __data_inverse(self,
data = self.random_state.normal(
0, 1, num_samples * data_row.shape[0]).reshape(
num_samples, data_row.shape[0])
data = data * self.scaler.scale_ + self.scaler.mean_
if self.sample_around_instance:
data = data * self.scaler.scale_ + data_row
else:
data = data * self.scaler.scale_ + self.scaler.mean_
categorical_features = self.categorical_features
first_row = data_row
else:
Expand Down

0 comments on commit 6946cbe

Please sign in to comment.