class_docstr: Explains predictions on tabular (i.e. matrix) data.
  For numerical features, perturb them by sampling from a Normal(0,1) and
  doing the inverse operation of mean-centering and scaling, according to the
  means and stds in the training data. For categorical features, perturb by
  sampling according to the training distribution, and making a binary
  feature that is 1 when the value is the same as the instance being
  explained.
class_docstr_tok: ["Explains","predictions","on","tabular","(","i.e",".","matrix",")","data",".","For","numerical","features",",","perturb","them","by","sampling","from","a","Normal","(","0,1",")","and","doing","the","inverse","operation","of","mean-centering","and","scaling",",","according","to","the","means","and","stds","in","the","training","data",".","For","categorical","features",",","perturb","by","sampling","according","to","the","training","distribution",",","and","making","a","binary","feature","that","is","1","when","the","value","is","the","same","as","the","instance","being","explained","."]
docstr: Init function.
  
  Args:
      training_data: numpy 2d array
      mode: "classification" or "regression"
      training_labels: labels for training data. Not required, but may be
          used by discretizer.
      feature_names: list of names (strings) corresponding to the columns
          in the training data.
      categorical_features: list of indices (ints) corresponding to the
          categorical columns. Everything else will be considered
          continuous. Values in these columns MUST be integers.
      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.
          If None, defaults to sqrt (number of columns) * 0.75
      kernel: similarity kernel that takes euclidean distances and kernel
          width as input and outputs weights in (0,1). If None, defaults to
          an exponential kernel.
      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',
          '1', ...
      feature_selection: feature selection method. can be
          'forward_selection', 'lasso_path', 'none' or 'auto'.
          See function 'explain_instance_with_data' in lime_base.py for
          details on what each of the options does.
      discretize_continuous: if True, all non-categorical features will
          be discretized into quartiles.
      discretizer: only matters if discretize_continuous is True
          and data is not sparse. Options are 'quartile', 'decile',
          'entropy' or a BaseDiscretizer instance.
      sample_around_instance: if True, will sample continuous features
          in perturbed samples from a normal centered at the instance
          being explained. Otherwise, the normal is centered on the mean
          of the feature data.
      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.
      training_data_stats: a dict object having the details of training data
          statistics. If None, training data information will be used, only matters
          if discretize_continuous is True. Must have the following keys:
          means", "mins", "maxs", "stds", "feature_values",
          "feature_frequencies"
docstr_tok: ["Init","function",".","Args",":","training_data",":","numpy","2d","array","mode",":","``","classification","''","or","``","regression","''","training_labels",":","labels","for","training","data",".","Not","required",",","but","may","be","used","by","discretizer",".","feature_names",":","list","of","names","(","strings",")","corresponding","to","the","columns","in","the","training","data",".","categorical_features",":","list","of","indices","(","ints",")","corresponding","to","the","categorical","columns",".","Everything","else","will","be","considered","continuous",".","Values","in","these","columns","MUST","be","integers",".","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",".","If","None",",","defaults","to","sqrt","(","number","of","columns",")","*","0.75","kernel",":","similarity","kernel","that","takes","euclidean","distances","and","kernel","width","as","input","and","outputs","weights","in","(","0,1",")",".","If","None",",","defaults","to","an","exponential","kernel",".","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","'",",","'","1","'",",","...","feature_selection",":","feature","selection","method",".","can","be","'forward_selection","'",",","'lasso_path","'",",","'none","'","or","'auto","'",".","See","function","'explain_instance_with_data","'","in","lime_base.py","for","details","on","what","each","of","the","options","does",".","discretize_continuous",":","if","True",",","all","non-categorical","features","will","be","discretized","into","quartiles",".","discretizer",":","only","matters","if","discretize_continuous","is","True","and","data","is","not","sparse",".","Options","are","'quartile","'",",","'decile","'",",","'entropy","'","or","a","BaseDiscretizer","instance",".","sample_around_instance",":","if","True",",","will","sample","continuous","features","in","perturbed","samples","from","a","normal","centered","at","the","instance","being","explained",".","Otherwise",",","the","normal","is","centered","on","the","mean","of","the","feature","data",".","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",".","training_data_stats",":","a","dict","object","having","the","details","of","training","data","statistics",".","If","None",",","training","data","information","will","be","used",",","only","matters","if","discretize_continuous","is","True",".","Must","have","the","following","keys",":","means","''",",","``","mins","''",",","``","maxs","''",",","``","stds","''",",","``","feature_values","''",",","``","feature_frequencies","''"]
code: def __init__(
      self,
      training_data,
      mode="classification",
      training_labels=None,
      feature_names=None,
      categorical_features=None,
      categorical_names=None,
      kernel_width=None,
      kernel=None,
      verbose=False,
      class_names=None,
      feature_selection="auto",
      discretize_continuous=True,
      discretizer="quartile",
      sample_around_instance=False,
      random_state=None,
      training_data_stats=None,
  ):
      """Init function.
  
      Args:
          training_data: numpy 2d array
          mode: "classification" or "regression"
          training_labels: labels for training data. Not required, but may be
              used by discretizer.
          feature_names: list of names (strings) corresponding to the columns
              in the training data.
          categorical_features: list of indices (ints) corresponding to the
              categorical columns. Everything else will be considered
              continuous. Values in these columns MUST be integers.
          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.
              If None, defaults to sqrt (number of columns) * 0.75
          kernel: similarity kernel that takes euclidean distances and kernel
              width as input and outputs weights in (0,1). If None, defaults to
              an exponential kernel.
          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',
              '1', ...
          feature_selection: feature selection method. can be
              'forward_selection', 'lasso_path', 'none' or 'auto'.
              See function 'explain_instance_with_data' in lime_base.py for
              details on what each of the options does.
          discretize_continuous: if True, all non-categorical features will
              be discretized into quartiles.
          discretizer: only matters if discretize_continuous is True
              and data is not sparse. Options are 'quartile', 'decile',
              'entropy' or a BaseDiscretizer instance.
          sample_around_instance: if True, will sample continuous features
              in perturbed samples from a normal centered at the instance
              being explained. Otherwise, the normal is centered on the mean
              of the feature data.
          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.
          training_data_stats: a dict object having the details of training data
              statistics. If None, training data information will be used, only matters
              if discretize_continuous is True. Must have the following keys:
              means", "mins", "maxs", "stds", "feature_values",
              "feature_frequencies"
      """
      self.random_state = check_random_state(random_state)
      self.mode = mode
      self.categorical_names = categorical_names or {}
      self.sample_around_instance = sample_around_instance
      self.training_data_stats = training_data_stats
  
      # Check and raise proper error in stats are supplied in non-descritized path
      if self.training_data_stats:
          self.validate_training_data_stats(self.training_data_stats)
  
      if categorical_features is None:
          categorical_features = []
      if feature_names is None:
          feature_names = [
              str(i) for i in range(training_data.shape[1])
          ]
  
      self.categorical_features = list(categorical_features)
      self.feature_names = list(feature_names)
  
      self.discretizer = None
      if discretize_continuous and not sp.sparse.issparse(
          training_data
      ):
          # Set the discretizer if training data stats are provided
          if self.training_data_stats:
              discretizer = StatsDiscretizer(
                  training_data,
                  self.categorical_features,
                  self.feature_names,
                  labels=training_labels,
                  data_stats=self.training_data_stats,
                  random_state=self.random_state,
              )
  
          if discretizer == "quartile":
              self.discretizer = QuartileDiscretizer(
                  training_data,
                  self.categorical_features,
                  self.feature_names,
                  labels=training_labels,
                  random_state=self.random_state,
              )
          elif discretizer == "decile":
              self.discretizer = DecileDiscretizer(
                  training_data,
                  self.categorical_features,
                  self.feature_names,
                  labels=training_labels,
                  random_state=self.random_state,
              )
          elif discretizer == "entropy":
              self.discretizer = EntropyDiscretizer(
                  training_data,
                  self.categorical_features,
                  self.feature_names,
                  labels=training_labels,
                  random_state=self.random_state,
              )
          elif isinstance(discretizer, BaseDiscretizer):
              self.discretizer = discretizer
          else:
              raise ValueError(
                  """Discretizer must be 'quartile',"""
                  + """ 'decile', 'entropy' or a"""
                  + """ BaseDiscretizer instance"""
              )
          self.categorical_features = list(
              range(training_data.shape[1])
          )
  
          # Get the discretized_training_data when the stats are not provided
          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]) * 0.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)
              values, frequencies = map(
                  list, zip(*(sorted(feature_count.items())))
              )
          else:
              values = training_data_stats["feature_values"][feature]
              frequencies = training_data_stats["feature_frequencies"][
                  feature
              ]
  
          self.feature_values[feature] = values
          self.feature_frequencies[feature] = np.array(
              frequencies
          ) / float(sum(frequencies))
          self.scaler.mean_[feature] = 0
          self.scaler.scale_[feature] = 1
  
imports: import collections
  import copy
  from functools import partial
  import json
  import warnings
  import numpy
  import scipy
  import sklearn
  import sklearn.preprocessing
  from sklearn.utils import check_random_state
  from pyDOE2 import lhs
  from scipy.stats.distributions import norm
  from lime.discretize import QuartileDiscretizer
  from lime.discretize import DecileDiscretizer
  from lime.discretize import EntropyDiscretizer
  from lime.discretize import BaseDiscretizer
  from lime.discretize import StatsDiscretizer
  from .None import explanation
  from .None import lime_base
label_desc: Use image node_id 1 to create a new LimeTabularExplainer object from inherited base classes: object with example: obj = LimeTabularExplainer(training_data, mode, training_labels, feature_names, categorical_features, categorical_names, kernel_width, kernel, verbose, class_names, feature_selection, discretize_continuous, discretizer, sample_around_instance, random_state, training_data_stats)