Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more tests for passing function to blackbox explainers #534

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions tests/common_tabular_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,18 @@ def verify_explain_model_throws_on_bad_pipeline_and_classes(self):
self.create_explainer(model.predict, x_train, is_function=True,
features=feature_names, classes=target_names)

def verify_explain_model_throws_on_bad_pipeline_and_no_classes(self):
# Verify that explain model throws when specifying a predict pipeline but no classes parameter
x_train, _, y_train, _, feature_names, _ = create_iris_data()
# Fit an SVM model
model = create_sklearn_svm_classifier(x_train, y_train)
self.test_logger.info('Running explain model for verify_explain_model_throws_on_bad_pipeline_and_no_classes')
with pytest.raises(
ValueError,
match="LIME Explainer requires classes to be specified if using a classification model"):
self.create_explainer(model.predict, x_train, is_function=True,
features=feature_names)

def verify_explain_model_throws_on_classifier_and_no_classes(self):
# Verify that explain model throws when specifying a classifier but no classes parameter
x_train, x_test, y_train, _, feature_names, _ = create_iris_data()
Expand Down
3 changes: 3 additions & 0 deletions tests/test_lime_explainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ def test_explain_model_throws_on_bad_classifier_and_classes(self):
def test_explain_model_throws_on_bad_pipeline_and_classes(self):
self.verify_tabular.verify_explain_model_throws_on_bad_pipeline_and_classes()

def test_explain_model_throws_on_bad_pipeline_and_no_classes(self):
self.verify_tabular.verify_explain_model_throws_on_bad_pipeline_and_no_classes()

def test_explain_model_throws_on_classifier_and_no_classes(self):
self.verify_tabular.verify_explain_model_throws_on_classifier_and_no_classes()

Expand Down
3 changes: 3 additions & 0 deletions tests/test_pfi_explainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ def test_explain_model_throws_on_bad_classifier_and_classes(self):
def test_explain_model_throws_on_bad_pipeline_and_classes(self):
self.verify_tabular.verify_explain_model_throws_on_bad_pipeline_and_classes()

def test_explain_model_throws_on_bad_pipeline_and_no_classes(self):
self.verify_tabular.verify_explain_model_throws_on_bad_pipeline_and_no_classes()

def test_explain_with_transformations_list_classification(self):
self.verify_tabular.verify_explain_model_transformations_list_classification(true_labels_required=True)

Expand Down