Skip to content

Commit

Permalink
made default value of kernel_width scaled by number of columns in tra…
Browse files Browse the repository at this point in the history
…ining data.
  • Loading branch information
Marco Tulio Ribeiro committed Aug 24, 2016
1 parent ad10414 commit 976695b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lime/lime_tabular.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class LimeTabularExplainer(object):
explained."""
def __init__(self, training_data, feature_names=None,
categorical_features=None, categorical_names=None,
kernel_width=3, verbose=False, class_names=None,
kernel_width=None, verbose=False, class_names=None,
feature_selection='auto', discretize_continuous=True):
"""Init function.
Expand All @@ -101,7 +101,8 @@ def __init__(self, training_data, feature_names=None,
categorical_names: map from int to list of names, where
categorical_names[x][y] represents the name of the yth value of
column x.
kernel_width: kernel width for the exponential kernel
kernel_width: kernel width for the exponential kernel.
If None, defaults to sqrt(number of columns) * 0.75
verbose: if true, print local prediction values from linear model
class_names: list of class names, ordered according to whatever the
classifier is using. If not present, class names will be '0',
Expand All @@ -128,6 +129,10 @@ def __init__(self, training_data, feature_names=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)

def kernel(d): return np.sqrt(np.exp(-(d**2) / kernel_width ** 2))
self.feature_selection = feature_selection
self.base = lime_base.LimeBase(kernel, verbose)
Expand Down

2 comments on commit 976695b

@MaSalwa
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hello @marcotcr
how did you come up with this formula of kernel width ?

@marcotcr
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This formula for the default value is just a rule-of-thumb that came out of nowhere : ).

Please sign in to comment.