-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtest_lime_tabular.py
36 lines (31 loc) · 1.41 KB
/
test_lime_tabular.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""Test LIME tabular method."""
from unittest import TestCase
import numpy as np
import dianna
from dianna.methods.lime_tabular import LIMETabular
from tests.utils import run_model
class LIMEOnTabular(TestCase):
"""Suite of LIME tests for the tabular case."""
def test_lime_tabular_classification_correct_output_shape(self):
"""Test the output of explainer."""
training_data = np.random.random((10, 2))
input_data = np.random.random(2)
feature_names = ["feature_1", "feature_2"]
explainer = LIMETabular(training_data,
mode ='classification',
feature_names=feature_names,
class_names = ["class_1", "class_2"])
exp = explainer.explain(
run_model,
input_data,
)
assert len(exp[0]) == len(feature_names)
def test_lime_tabular_regression_correct_output_shape(self):
"""Test the output of explainer."""
training_data = np.random.random((10, 2))
input_data = np.random.random(2)
feature_names = ["feature_1", "feature_2"]
exp = dianna.explain_tabular(run_model, input_tabular=input_data, method='lime',
mode ='regression', training_data = training_data,
feature_names=feature_names, class_names=['class_1'])
assert len(exp) == len(feature_names)