-
Notifications
You must be signed in to change notification settings - Fork 85
/
explanation_utils.py
31 lines (23 loc) · 1.76 KB
/
explanation_utils.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
# ---------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------
# Defines common test utilities for validating explanation objects
def validate_global_classification_explanation_shape(explanation, evaluation_examples,
num_classes=2, include_local=True):
assert explanation._global_importance_values.shape[0] == evaluation_examples.shape[1]
assert explanation._per_class_values.shape[0] == num_classes
assert explanation._per_class_values.shape[1] == evaluation_examples.shape[1]
if include_local:
validate_local_classification_explanation_shape(explanation, evaluation_examples, num_classes)
def validate_local_classification_explanation_shape(explanation, evaluation_examples, num_classes=2):
assert explanation._local_importance_values.shape[0] == num_classes
assert explanation._local_importance_values.shape[1] == evaluation_examples.shape[0]
assert explanation._local_importance_values.shape[2] == evaluation_examples.shape[1]
def validate_global_regression_explanation_shape(explanation, evaluation_examples,
num_classes=2, include_local=True):
assert explanation._global_importance_values.shape[0] == evaluation_examples.shape[1]
if include_local:
validate_local_regression_explanation_shape(explanation, evaluation_examples, num_classes)
def validate_local_regression_explanation_shape(explanation, evaluation_examples, num_classes=2):
assert explanation._local_importance_values.shape[0] == evaluation_examples.shape[0]
assert explanation._local_importance_values.shape[1] == evaluation_examples.shape[1]