Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
max_len = max(max_len, len(similar_word[0]))
total_len += max_len + 1
data_type = '
exp = AnchorBaseBeam.anchor_beam(sample_fn, delta=delta,
epsilon=tau, batch_size=batch_size,
desired_confidence=threshold, **kwargs) # type: Any
exp['instance'] = image
exp['prediction'] = self.predict_fn(np.reshape(image, (1,) + self.image_shape))[0]
# overlay image with anchor mask and do same for the examples
anchor = AnchorImage.overlay_mask(image, segments, exp['feature'])
cover_options = ['covered', 'covered_true', 'covered_false', 'uncovered_true', 'uncovered_false']
for ex in exp['examples']:
for opt in cover_options:
tmp = [AnchorImage.overlay_mask(image, segments, list(np.where(ex[opt][i] == 1)[0]))
for i in range(ex[opt].shape[0])]
ex[opt] = tmp
exp = AnchorExplanation('image', exp)
# output explanation dictionary
explanation = {}
explanation['anchor'] = anchor
explanation['segments'] = segments
explanation['precision'] = exp.precision()
explanation['coverage'] = exp.coverage()
explanation['raw'] = exp.exp_map
explanation['meta'] = {}
explanation['meta']['name'] = self.__class__.__name__
return explanation
-------
explanation
Dictionary containing the anchor explaining the instance with additional metadata
"""
# build sampling function and ...
# ... mapping = (feature column, flag for categorical/ordinal feature, feature value or bin value)
sample_fn, mapping = self.get_sample_fn(X, desired_label=desired_label)
# get anchors and add metadata
exp = AnchorBaseBeam.anchor_beam(sample_fn, delta=delta, epsilon=tau,
batch_size=batch_size, desired_confidence=threshold,
max_anchor_size=max_anchor_size, **kwargs) # type: Any
self.add_names_to_exp(exp, mapping)
exp['instance'] = X
exp['prediction'] = self.predict_fn(X.reshape(1, -1))[0]
exp = AnchorExplanation('tabular', exp)
# output explanation dictionary
explanation = {}
explanation['names'] = exp.names()
explanation['precision'] = exp.precision()
explanation['coverage'] = exp.coverage()
explanation['raw'] = exp.exp_map
explanation['meta'] = {}
explanation['meta']['name'] = self.__class__.__name__
return explanation