Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
explanations.
"""
indexed_string = (IndexedCharacters(
text_instance, bow=self.bow, mask_string=self.mask_string)
if self.char_level else
IndexedString(text_instance, bow=self.bow,
split_expression=self.split_expression,
mask_string=self.mask_string))
domain_mapper = TextDomainMapper(indexed_string)
data, yss, distances = self.__data_labels_distances(
indexed_string, classifier_fn, num_samples,
distance_metric=distance_metric)
if self.class_names is None:
self.class_names = [str(x) for x in range(yss[0].shape[0])]
ret_exp = explanation.Explanation(domain_mapper=domain_mapper,
class_names=self.class_names,
random_state=self.random_state)
ret_exp.predict_proba = yss[0]
if top_labels:
labels = np.argsort(yss[0])[-top_labels:]
ret_exp.top_labels = list(labels)
ret_exp.top_labels.reverse()
for label in labels:
(ret_exp.intercept[label],
ret_exp.local_exp[label],
ret_exp.score, ret_exp.local_pred) = self.base.explain_instance_with_data(
data, yss, distances, label, num_features,
model_regressor=model_regressor,
feature_selection=self.feature_selection)
return ret_exp
discretized_feature_names = None
if self.discretizer is not None:
categorical_features = range(data.shape[1])
discretized_instance = self.discretizer.discretize(data_row)
discretized_feature_names = copy.deepcopy(feature_names)
for f in self.discretizer.names:
discretized_feature_names[f] = self.discretizer.names[f][int(
discretized_instance[f])]
domain_mapper = TableDomainMapper(feature_names,
values,
scaled_data[0],
categorical_features=categorical_features,
discretized_feature_names=discretized_feature_names,
feature_indexes=feature_indexes)
ret_exp = explanation.Explanation(domain_mapper,
mode=self.mode,
class_names=self.class_names)
ret_exp.scaled_data = scaled_data
if self.mode == "classification":
ret_exp.predict_proba = yss[0]
if top_labels:
labels = np.argsort(yss[0])[-top_labels:]
ret_exp.top_labels = list(labels)
ret_exp.top_labels.reverse()
else:
ret_exp.predicted_value = predicted_value
ret_exp.min_value = min_y
ret_exp.max_value = max_y
labels = [0]
for label in labels:
(ret_exp.intercept[label],