Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if(self.training_data_stats is None):
discretized_training_data = self.discretizer.discretize(
training_data)
if kernel_width is None:
kernel_width = np.sqrt(training_data.shape[1]) * .75
kernel_width = float(kernel_width)
if kernel is None:
def kernel(d, kernel_width):
return np.sqrt(np.exp(-(d ** 2) / kernel_width ** 2))
kernel_fn = partial(kernel, kernel_width=kernel_width)
self.feature_selection = feature_selection
self.base = lime_base.LimeBase(kernel_fn, verbose, random_state=self.random_state)
self.class_names = class_names
# Though set has no role to play if training data stats are provided
self.scaler = sklearn.preprocessing.StandardScaler(with_mean=False)
self.scaler.fit(training_data)
self.feature_values = {}
self.feature_frequencies = {}
for feature in self.categorical_features:
if training_data_stats is None:
if self.discretizer is not None:
column = discretized_training_data[:, feature]
else:
column = training_data[:, feature]
feature_count = collections.Counter(column)
otherwise.
random_state: an integer or numpy.RandomState that will be used to
generate random numbers. If None, the random state will be
initialized using the internal numpy seed.
char_level: an boolean identifying that we treat each character
as an independent occurence in the string
"""
if kernel is None:
def kernel(d, kernel_width):
return np.sqrt(np.exp(-(d ** 2) / kernel_width ** 2))
kernel_fn = partial(kernel, kernel_width=kernel_width)
self.random_state = check_random_state(random_state)
self.base = lime_base.LimeBase(kernel_fn, verbose,
random_state=self.random_state)
self.class_names = class_names
self.vocabulary = None
self.feature_selection = feature_selection
self.bow = bow
self.mask_string = mask_string
self.split_expression = split_expression
self.char_level = char_level
details on what each of the options does.
random_state: an integer or numpy.RandomState that will be used to
generate random numbers. If None, the random state will be
initialized using the internal numpy seed.
"""
kernel_width = float(kernel_width)
if kernel is None:
def kernel(d, kernel_width):
return np.sqrt(np.exp(-(d ** 2) / kernel_width ** 2))
kernel_fn = partial(kernel, kernel_width=kernel_width)
self.random_state = check_random_state(random_state)
self.feature_selection = feature_selection
self.base = lime_base.LimeBase(kernel_fn, verbose, random_state=self.random_state)
from __future__ import unicode_literals
import itertools,re,copy,types,os
import numpy as np
import scipy as sp
import sklearn
import skimage as si
from skimage import io,segmentation,util
import streakFunctions as streak
from time import time
from lime import explanation
from lime import lime_base
from lime import lime_image
class MyLimeBase(lime_base.LimeBase):
'''
Extend LimeBase class with a new feature selection method that supports streaming_greedy feature selection
This is described in Section A.8 of the paper
'''
def feature_selection(self, data, labels, weights, num_features, method):
"""Selects features for the model. see explain_instance_with_data to
understand the parameters."""
tstart = time()
# print "method is %s" % method
if method in ['thresholded_greedy','streaming_greedy','streaming_regression','streaming','STREAK','streak','streak_lime']:
out = self.thresholded_greedy(data,labels,weights,num_features)
tend = time()
self.selection_time = tend - tstart
return out
else:
# print "Using LimeBase.feature_selection"