Skip to content

Commit

Permalink
Adjust demo notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
Emanuel Metzenthin committed Oct 8, 2020
1 parent 1aa96fb commit ba6eeea
Show file tree
Hide file tree
Showing 17 changed files with 87 additions and 108 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ A given example instance is perturbed (i.e. parts of its features are 'switched

The LIME package only supports image, text and tabular data. We extended it to be able to deal with time series data.

![Results on the coffee dataset](/demo/results/coffee/coffee_24_10_noise.JPG)
## Demo

![Results on the ecg dataset](/demo/results/ecg/ecg_17_5_total_mean.JPG)
See the demo [notebook](demo/LIME-Pipeline.ipynb) for how to use the module.
185 changes: 81 additions & 104 deletions demo/LIME-Pipeline.ipynb

Large diffs are not rendered by default.

Binary file removed demo/results/coffee/coffee_10_5_noise.JPG
Binary file not shown.
Binary file removed demo/results/coffee/coffee_12_5_mean.JPG
Binary file not shown.
Binary file removed demo/results/coffee/coffee_12_5_noise.JPG
Binary file not shown.
Binary file removed demo/results/coffee/coffee_12_5_total_mean.JPG
Binary file not shown.
Binary file removed demo/results/coffee/coffee_24_10_mean.JPG
Binary file not shown.
Binary file removed demo/results/coffee/coffee_24_10_noise.JPG
Binary file not shown.
Binary file removed demo/results/coffee/coffee_24_10_total_mean.JPG
Binary file not shown.
Binary file removed demo/results/coffee/coffee_50_20_noise.JPG
Binary file not shown.
Binary file removed demo/results/coffee_dataset_plot.JPG
Binary file not shown.
Binary file removed demo/results/ecg/ecg_17_5_mean.JPG
Binary file not shown.
Binary file removed demo/results/ecg/ecg_17_5_noise.JPG
Binary file not shown.
Binary file removed demo/results/ecg/ecg_17_5_total_mean.JPG
Binary file not shown.
Binary file removed demo/results/ecg_dataset_plot.JPG
Binary file not shown.
Binary file removed demo/results/total_mean_plot.JPG
Binary file not shown.
6 changes: 4 additions & 2 deletions lime_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,19 @@ def distance_fn(x):
values_per_slice = math.ceil(len(timeseries) / num_slices)
deact_per_slice = np.random.randint(1, num_slices + 1, num_samples - 1)
perturbation_matrix = np.ones((num_samples, num_slices))
features_range = range(num_slices)
original_data = [timeseries.copy()]

for i, num_inactive in enumerate(deact_per_slice, start=1):
# choose random slices indexes to deactivate
inactive_idxs = np.random.choice(len(num_slices), num_inactive, replace=False)
inactive_idxs = np.random.choice(features_range, num_inactive, replace=False)
perturbation_matrix[i, inactive_idxs] = 0
tmp_series = timeseries.copy()

for idx in inactive_idxs:
start_idx = idx * values_per_slice
end_idx = start_idx + values_per_slice
end_idx = min(end_idx, len(timeseries))

if replacement_method == 'mean':
# use mean of slice as inactive
Expand All @@ -152,7 +154,7 @@ def distance_fn(x):
tmp_series[start_idx:end_idx] = np.random.uniform(
tmp_series.min(),
tmp_series.max(),
values_per_slice)
end_idx - start_idx)
elif replacement_method == 'total_mean':
# use total series mean as inactive
tmp_series[start_idx:end_idx] = tmp_series.mean()
Expand Down

0 comments on commit ba6eeea

Please sign in to comment.