Model explainer
Explainer
Parent class for the explainers
Source code in template_vision/monitoring/model_explainer.py
__init__(*args, **kwargs)
explain_instance(content, **kwargs)
Explains a prediction
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content |
Image
|
Image to be explained |
required |
Returns: (?): An explanation object
Source code in template_vision/monitoring/model_explainer.py
explain_instance_as_html(content, **kwargs)
Explains a prediction - returns an HTML object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content |
Image
|
Image to be explained |
required |
Returns: str: An HTML code with the explanation
Source code in template_vision/monitoring/model_explainer.py
explain_instance_as_json(content, **kwargs)
Explains a prediction - returns an JSON serializable object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content |
str
|
Text to be explained |
required |
Returns: str: A JSON serializable object with the explanation
Source code in template_vision/monitoring/model_explainer.py
LimeExplainer
Bases: Explainer
Lime Explainer wrapper class
Source code in template_vision/monitoring/model_explainer.py
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 |
|
__init__(model, model_conf)
Initialization
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
Type[ModelClassifierMixin]
|
A model instance with predict & predict_proba functions, and list_classes attribute |
required |
model_conf |
dict
|
The model's configuration |
required |
Raises:
ValueError: If the provided model is not a classifier
TypeError: If the provided model does not implement a predict_proba
function
TypeError: If the provided model does not have a list_classes
attribute
Source code in template_vision/monitoring/model_explainer.py
classifier_fn(content_arrays)
Function to get probabilities from a list of (not preprocessed) images
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content_arrays |
ndarray
|
images to be considered |
required |
Returns: np.array: probabilities
Source code in template_vision/monitoring/model_explainer.py
explain_instance(content, class_index=None, num_samples=100, batch_size=100, hide_color=0, **kwargs)
Explains a prediction
This function calls the Lime module. It generates neighborhood data by randomly perturbing features from the instance. Then, it learns locally weighted linear models on this neighborhood data to explain each of the classes in an interpretable way.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img |
Image
|
Image to be explained |
required |
Kwargs: class_index (int): for classification only. Class or label index to be considered. num_samples (int): size of the neighborhood to learn the linear model (cf. Lime documentation) batch_size (int): classifier_fn will be called on batches of this size (cf. Lime documentation) hide_color (?): TODO Returns: (?): An explanation object
Source code in template_vision/monitoring/model_explainer.py
explain_instance_as_html(content, **kwargs)
Explains a prediction - returns an HTML object ** NOT IMPLEMENTED **
Source code in template_vision/monitoring/model_explainer.py
explain_instance_as_json(content, **kwargs)
Explains a prediction - returns an JSON serializable object ** NOT IMPLEMENTED **