-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathconstants.py
More file actions
285 lines (214 loc) · 8.21 KB
/
constants.py
File metadata and controls
285 lines (214 loc) · 8.21 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# ---------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------
"""Defines constants for interpret community."""
from enum import Enum
class ExplanationParams(object):
"""Provide constants for explanation parameters."""
EXPECTED_VALUES = 'expected_values'
CLASSES = 'classes'
class ExplainType(object):
"""Provide constants for model and explainer type information, useful for visualization."""
CLASSIFICATION = 'classification'
DATA = 'data_type'
EXPLAIN = 'explain_type'
EXPLAINER = 'explainer'
FUNCTION = 'function'
GLOBAL = 'global'
HAN = 'han'
IS_ENG = 'is_engineered'
IS_RAW = 'is_raw'
LIME = 'lime'
LOCAL = 'local'
METHOD = 'method'
MIMIC = 'mimic'
MODEL = 'model_type'
MODEL_CLASS = 'model_class'
MODEL_TASK = 'model_task'
PFI = 'pfi'
REGRESSION = 'regression'
SHAP = 'shap'
SHAP_DEEP = 'shap_deep'
SHAP_KERNEL = 'shap_kernel'
SHAP_TREE = 'shap_tree'
SHAP_LINEAR = 'shap_linear'
TABULAR = 'tabular'
class ExplainParams(object):
"""Provide constants for interpret community (init, explain_local and explain_global) parameters."""
BATCH_SIZE = 'batch_size'
CLASSES = 'classes'
CLASSIFICATION = 'classification'
EVAL_DATA = 'eval_data'
EVAL_Y_PRED = 'eval_y_predicted'
EVAL_Y_PRED_PROBA = 'eval_y_predicted_proba'
EXPECTED_VALUES = 'expected_values'
EXPLAIN_SUBSET = 'explain_subset'
EXPLANATION_ID = 'explanation_id'
FEATURES = 'features'
GLOBAL_IMPORTANCE_NAMES = 'global_importance_names'
GLOBAL_IMPORTANCE_VALUES = 'global_importance_values'
GLOBAL_IMPORTANCE_RANK = 'global_importance_rank'
GLOBAL_NAMES = 'global_names'
GLOBAL_VALUES = 'global_values'
GLOBAL_RANK = 'global_rank'
ID = 'id'
INCLUDE_LOCAL = 'include_local'
INIT_DATA = 'init_data'
IS_ENG = 'is_engineered'
IS_LOCAL_SPARSE = 'is_local_sparse'
IS_RAW = 'is_raw'
LOCAL_EXPLANATION = 'local_explanation'
LOCAL_IMPORTANCE_VALUES = 'local_importance_values'
METHOD = 'method'
MODEL_ID = 'model_id'
MODEL_TASK = 'model_task'
MODEL_TYPE = 'model_type'
NUM_CLASSES = 'num_classes'
NUM_EXAMPLES = 'num_examples'
NUM_FEATURES = 'num_features'
PER_CLASS_NAMES = 'per_class_names'
PER_CLASS_RANK = 'per_class_rank'
PER_CLASS_VALUES = 'per_class_values'
PROBABILITIES = 'probabilities'
SAMPLING_POLICY = 'sampling_policy'
SHAP_VALUES_OUTPUT = 'shap_values_output'
@classmethod
def get_serializable(cls):
"""Return only the ExplainParams properties that have meaningful data values for serialization.
:return: A set of property names, e.g., 'GLOBAL_IMPORTANCE_VALUES', 'MODEL_TYPE', etc.
:rtype: set{str}
"""
return (set(filter(lambda x: not x.startswith('__') and not callable(getattr(cls, x)),
vars(cls).keys())) - set(['DATA_MAPPER', 'DATA_MAPPER_INTERNAL']))
class Defaults(object):
"""Provide constants for default values to explain methods."""
AUTO = 'auto'
DEFAULT_BATCH_SIZE = 100
# hdbscan is an unsupervised learning library to find the optimal number of clusters in a dataset
# See this github repo for more details: https://github.com/scikit-learn-contrib/hdbscan
HDBSCAN = 'hdbscan'
MAX_DIM = 50
class Attributes(object):
"""Provide constants for attributes."""
EXPECTED_VALUE = 'expected_value'
class Dynamic(object):
"""Provide constants for dynamically generated classes."""
GLOBAL_EXPLANATION = 'DynamicGlobalExplanation'
LOCAL_EXPLANATION = 'DynamicLocalExplanation'
class Tensorflow(object):
"""Provide TensorFlow and TensorBoard related constants."""
CPU0 = '/CPU:0'
TFLOG = 'tflog'
class SKLearn(object):
"""Provide scikit-learn related constants."""
EXAMPLES = 'examples'
LABELS = 'labels'
PREDICTIONS = 'predictions'
PREDICT_PROBA = 'predict_proba'
class Spacy(object):
"""Provide spaCy related constants."""
EN = 'en'
NER = 'ner'
TAGGER = 'tagger'
class ModelTask(str, Enum):
"""Provide model task constants. Can be 'classification', 'regression', or 'unknown'.
By default the model domain is inferred if 'unknown', but this can be overridden if you specify
'classification' or 'regression'.
"""
Classification = 'classification'
Regression = 'regression'
Unknown = 'unknown'
class LightGBMParams(object):
"""Provide constants for LightGBM."""
CATEGORICAL_FEATURE = 'categorical_feature'
N_JOBS = 'n_jobs'
ALL = [CATEGORICAL_FEATURE, N_JOBS]
class LinearExplainableModelParams(object):
"""Provide constants for LinearExplainableModel."""
SPARSE_DATA = 'sparse_data'
ALL = [SPARSE_DATA]
class ShapValuesOutput(str, Enum):
"""Provide constants for the SHAP values output from the explainer.
Can be 'default', 'probability' or 'teacher_probability'. If 'teacher_probability' is specified,
we use the probabilities from the teacher model.
"""
DEFAULT = 'default'
PROBABILITY = 'probability'
TEACHER_PROBABILITY = 'teacher_probability'
class ExplainableModelType(str, Enum):
"""Provide constants for the explainable model type."""
TREE_EXPLAINABLE_MODEL_TYPE = 'tree_explainable_model_type'
LINEAR_EXPLAINABLE_MODEL_TYPE = 'linear_explainable_model_type'
class MimicSerializationConstants(object):
"""Provide internal class that defines fields used for MimicExplainer serialization."""
FUNCTION = 'function'
IDENTITY = '_identity'
INITIALIZATION_EXAMPLES = 'initialization_examples'
LOGGER = '_logger'
MODEL = 'model'
ORIGINAL_EVAL_EXAMPLES = '_original_eval_examples'
PREDICT_PROBA_FLAG = 'predict_proba_flag'
TIMESTAMP_FEATURIZER = '_timestamp_featurizer'
RESET_INDEX = 'reset_index'
ALLOW_ALL_TRANSFORMATIONS = '_allow_all_transformations'
enum_properties = ['_shap_values_output']
nonify_properties = ['_logger', 'model', 'function', 'initialization_examples',
'_original_eval_examples', '_timestamp_featurizer']
save_properties = ['surrogate_model']
class LightGBMSerializationConstants(object):
"""Provide internal class that defines fields used for MimicExplainer serialization."""
IDENTITY = '_identity'
LOGGER = '_logger'
MODEL_STR = 'model_str'
MULTICLASS = 'multiclass'
REGRESSION = 'regression'
TREE_EXPLAINER = '_tree_explainer'
OBJECTIVE = 'objective'
enum_properties = ['_shap_values_output']
nonify_properties = [LOGGER, TREE_EXPLAINER]
save_properties = ['_lgbm']
class DNNFramework(object):
"""Provide DNN framework constants."""
TENSORFLOW = 'tensorflow'
PYTORCH = 'pytorch'
class InterpretData(object):
"""Provide Data and Visualize constants for interpret core."""
BASE_VALUE = 'Base Value'
EXPLANATION_TYPE = 'explanation_type'
EXTRA = 'extra'
FEATURE_LIST = 'feature_list'
GLOBAL_FEATURE_IMPORTANCE = 'global_feature_importance'
INTERCEPT = 'intercept'
LOCAL_FEATURE_IMPORTANCE = 'local_feature_importance'
MLI = 'mli'
NAMES = 'names'
OVERALL = 'overall'
PERF = 'perf'
SCORES = 'scores'
SPECIFIC = 'specific'
TYPE = 'type'
UNIVARIATE = 'univariate'
VALUE = 'value'
VALUES = 'values'
EXPLANATION_CLASS_DIMENSION = 'explanation_class_dimension'
MULTICLASS = 'multiclass'
SINGLE = 'single'
class Extension(object):
"""Provide constants for extensions to interpret package."""
BLACKBOX = 'blackbox'
GLASSBOX = 'model'
GLOBAL = 'global'
GREYBOX = 'specific'
LOCAL = 'local'
class SHAPDefaults(object):
"""Provide constants for default values to SHAP."""
INDEPENDENT = 'independent'
class ResetIndex(str, Enum):
"""Provide index column handling constants. Can be 'ignore', 'reset' or 'reset_teacher'.
By default the index column is ignored, but you can override to reset it and make it a
feature column that is then featurized to numeric, or reset it and ignore it during
featurization but set it as the index when calling predict on the original model.
"""
Ignore = 'ignore'
Reset = 'reset'
ResetTeacher = 'reset_teacher'