docstr: Build the LIME tabular explainer.
  For now, the parameters used to instantiate this class are exactly those of
  lime.lime_tabular.LimeTabularExplainer. Original documentation can be found here:
  https://lime-ml.readthedocs.io/en/latest/lime.html#module-lime.lime_tabular
  
  Args:
      training_data (np.ndarray): 2d Numpy array representing the training data 
          (or some representative subset)
      predict_fn (Callable): A function that takes in a 1D numpy array and outputs a vector
          of probabilities which should sum to 1.
      feature_names (list): The names of the columns of the training data
      mode (str): Whether the problem is 'classification' or 'regression'
      training_labels (list): Training labels, which can be used by the continuous feature
          discretizer
      categorical_features (list): Integer list indicating the indices of categorical features
      dict_categorical_mapping (dict): Mapping of integer index of categorical feature
          (same as from categorical_features) to a list of values for that column.
          So dict_categorical_mapping[x][y] is the yth value of column x.
      kernel_width (float): Width of the exponential kernel used in the LIME loss function
      verbose (bool): Control verbosity. If true, local prediction values of the LIME model
          are printed
      class_names (list): Class names (positional index corresponding to class index)
      feature_selection (str): Feature selection method. See original docs for more details
      discretize_continuous (True): Whether to discretize non-categorical features
      discretizer (str): Type of discretization. See original docs for more details
      sample_around_instance (True): 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 (int): The random seed to generate random numbers during training
  
  Returns:
      None
docstr_tok: ["Build","the","LIME","tabular","explainer",".","For","now",",","the","parameters","used","to","instantiate","this","class","are","exactly","those","of","lime.lime_tabular.LimeTabularExplainer",".","Original","documentation","can","be","found","here",":","https",":","\/\/lime-ml.readthedocs.io\/en\/latest\/lime.html","#","module-lime.lime_tabular","Args",":","training_data","(","np.ndarray",")",":","2d","Numpy","array","representing","the","training","data","(","or","some","representative","subset",")","predict_fn","(","Callable",")",":","A","function","that","takes","in","a","1D","numpy","array","and","outputs","a","vector","of","probabilities","which","should","sum","to","1.","feature_names","(","list",")",":","The","names","of","the","columns","of","the","training","data","mode","(","str",")",":","Whether","the","problem","is","'classification","'","or","'regression'","training_labels","(","list",")",":","Training","labels",",","which","can","be","used","by","the","continuous","feature","discretizer","categorical_features","(","list",")",":","Integer","list","indicating","the","indices","of","categorical","features","dict_categorical_mapping","(","dict",")",":","Mapping","of","integer","index","of","categorical","feature","(","same","as","from","categorical_features",")","to","a","list","of","values","for","that","column",".","So","dict_categorical_mapping","[","x","]","[","y","]","is","the","yth","value","of","column","x.","kernel_width","(","float",")",":","Width","of","the","exponential","kernel","used","in","the","LIME","loss","function","verbose","(","bool",")",":","Control","verbosity",".","If","true",",","local","prediction","values","of","the","LIME","model","are","printed","class_names","(","list",")",":","Class","names","(","positional","index","corresponding","to","class","index",")","feature_selection","(","str",")",":","Feature","selection","method",".","See","original","docs","for","more","details","discretize_continuous","(","True",")",":","Whether","to","discretize","non-categorical","features","discretizer","(","str",")",":","Type","of","discretization",".","See","original","docs","for","more","details","sample_around_instance","(","True",")",":","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","(","int",")",":","The","random","seed","to","generate","random","numbers","during","training","Returns",":","None"]
code: def build_explainer(
      self,
      training_data: np.ndarray,
      predict_fn: Callable[[np.ndarray], np.ndarray],
      feature_names: Optional[List[str]] = None,
      mode: str = MODE.CLASSIFICATION,
      training_labels: Optional[List[int]] = None,
      categorical_features: Optional[List[int]] = None,
      dict_categorical_mapping: Optional[Dict[int, List[str]]] = None,
      kernel_width: Optional[float] = None,
      verbose: bool = False,
      class_names: Optional[List[str]] = None,
      feature_selection: str = "auto",
      discretize_continuous: bool = True,
      discretizer: str = "quartile",
      sample_around_instance: bool = False,
      random_state: Optional[int] = None,
      **kwargs,
  ):
      """
      Build the LIME tabular explainer.
      For now, the parameters used to instantiate this class are exactly those of
      lime.lime_tabular.LimeTabularExplainer. Original documentation can be found here:
      https://lime-ml.readthedocs.io/en/latest/lime.html#module-lime.lime_tabular
  
      Args:
          training_data (np.ndarray): 2d Numpy array representing the training data
              (or some representative subset)
          predict_fn (Callable): A function that takes in a 1D numpy array and outputs a vector
              of probabilities which should sum to 1.
          feature_names (list): The names of the columns of the training data
          mode (str): Whether the problem is 'classification' or 'regression'
          training_labels (list): Training labels, which can be used by the continuous feature
              discretizer
          categorical_features (list): Integer list indicating the indices of categorical features
          dict_categorical_mapping (dict): Mapping of integer index of categorical feature
              (same as from categorical_features) to a list of values for that column.
              So dict_categorical_mapping[x][y] is the yth value of column x.
          kernel_width (float): Width of the exponential kernel used in the LIME loss function
          verbose (bool): Control verbosity. If true, local prediction values of the LIME model
              are printed
          class_names (list): Class names (positional index corresponding to class index)
          feature_selection (str): Feature selection method. See original docs for more details
          discretize_continuous (True): Whether to discretize non-categorical features
          discretizer (str): Type of discretization. See original docs for more details
          sample_around_instance (True): 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 (int): The random seed to generate random numbers during training
  
      Returns:
          None
      """
  
      if mode not in self.available_modes:
          msg = "Mode must be one of {}! Failed to build explainer".format(
              self.available_modes
          )
          raise UnsupportedModeError(msg)
  
      if verbose:
          if not feature_names:
              warnings.warn(
                  message="Column names are not specified! Explanations will "
                  "refer to columns by their indices."
              )
          if not class_names:
              warnings.warn(
                  message="Class names are not specified! Explanations will refer to classes"
                  "by their indices."
              )
  
      self.predict_fn = predict_fn
      self.explainer_object = OriginalLimeTabularExplainer(
          training_data=training_data,
          mode=mode,
          training_labels=training_labels,
          feature_names=feature_names,
          categorical_features=categorical_features,
          categorical_names=dict_categorical_mapping,
          kernel_width=kernel_width,
          verbose=verbose,
          class_names=class_names,
          feature_selection=feature_selection,
          discretize_continuous=discretize_continuous,
          discretizer=discretizer,
          sample_around_instance=sample_around_instance,
          random_state=random_state,
      )
      self.num_class = training_data.shape[1]
      self.mode = mode
  
      if verbose:
          warnings.warn(message="Explainer built successfully!")
  
file_path: contextual-ai/xai/explainer/tabular/lime_tabular_explainer.py
imports: import warnings
  import dill
  import numpy
  from lime.lime_tabular import LimeTabularExplainer
  from typing import List, Dict, Optional, Callable
  from xai.explainer.abstract_explainer import AbstractExplainer
  from xai.explainer.constants import MODE
  from xai.explainer.explainer_exceptions import ExplainerUninitializedError, UnsupportedModeError
  from xai.explainer.utils import explanation_to_json
label_desc: Use image node_id 2 for calling the LimeTabularExplainer obj's underlying member method code with example usage: obj.build_explainer(training_data, predict_fn, feature_names, mode, training_labels, categorical_features, dict_categorical_mapping, kernel_width, verbose, class_names, feature_selection, discretize_continuous, discretizer, sample_around_instance, random_state) without return types