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: Generates a neighborhood around a prediction.
  
  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.
  
  Args:
      data_row: 1d numpy array, corresponding to a row
      num_samples: size of the neighborhood to learn the linear model
      sampling_method: 'gaussian' or 'lhs'
  
  Returns:
      A tuple (data, inverse), where:
          data: dense num_samples * K matrix, where categorical features
          are encoded with either 0 (not equal to the corresponding value
          in data_row) or 1. The first row is the original instance.
          inverse: same as data, except the categorical features are not
          binary, but categorical (as the original data)
docstr_tok: ["Generates","a","neighborhood","around","a","prediction",".","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",".","Args",":","data_row",":","1d","numpy","array",",","corresponding","to","a","row","num_samples",":","size","of","the","neighborhood","to","learn","the","linear","model","sampling_method",":","'gaussian","'","or","'lhs'","Returns",":","A","tuple","(","data",",","inverse",")",",","where",":","data",":","dense","num_samples","*","K","matrix",",","where","categorical","features","are","encoded","with","either","0","(","not","equal","to","the","corresponding","value","in","data_row",")","or","1",".","The","first","row","is","the","original","instance",".","inverse",":","same","as","data",",","except","the","categorical","features","are","not","binary",",","but","categorical","(","as","the","original","data",")"]
code: def __data_inverse(self, data_row, num_samples, sampling_method):
      """Generates a neighborhood around a prediction.
  
      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.
  
      Args:
          data_row: 1d numpy array, corresponding to a row
          num_samples: size of the neighborhood to learn the linear model
          sampling_method: 'gaussian' or 'lhs'
  
      Returns:
          A tuple (data, inverse), where:
              data: dense num_samples * K matrix, where categorical features
              are encoded with either 0 (not equal to the corresponding value
              in data_row) or 1. The first row is the original instance.
              inverse: same as data, except the categorical features are not
              binary, but categorical (as the original data)
      """
      is_sparse = sp.sparse.issparse(data_row)
      if is_sparse:
          num_cols = data_row.shape[1]
          data = sp.sparse.csr_matrix(
              (num_samples, num_cols), dtype=data_row.dtype
          )
      else:
          num_cols = data_row.shape[0]
          data = np.zeros((num_samples, num_cols))
      categorical_features = range(num_cols)
      if self.discretizer is None:
          instance_sample = data_row
          scale = self.scaler.scale_
          mean = self.scaler.mean_
          if is_sparse:
              # Perturb only the non-zero values
              non_zero_indexes = data_row.nonzero()[1]
              num_cols = len(non_zero_indexes)
              instance_sample = data_row[:, non_zero_indexes]
              scale = scale[non_zero_indexes]
              mean = mean[non_zero_indexes]
  
          if sampling_method == "gaussian":
              data = self.random_state.normal(
                  0, 1, num_samples * num_cols
              ).reshape(num_samples, num_cols)
              data = np.array(data)
          elif sampling_method == "lhs":
              data = lhs(num_cols, samples=num_samples).reshape(
                  num_samples, num_cols
              )
              means = np.zeros(num_cols)
              stdvs = np.array([1] * num_cols)
              for i in range(num_cols):
                  data[:, i] = norm(loc=means[i], scale=stdvs[i]).ppf(
                      data[:, i]
                  )
              data = np.array(data)
          else:
              warnings.warn(
                  """Invalid input for sampling_method.
                                   Defaulting to Gaussian sampling.""",
                  UserWarning,
              )
              data = self.random_state.normal(
                  0, 1, num_samples * num_cols
              ).reshape(num_samples, num_cols)
              data = np.array(data)
  
          if self.sample_around_instance:
              data = data * scale + instance_sample
          else:
              data = data * scale + mean
          if is_sparse:
              if num_cols == 0:
                  data = sp.sparse.csr_matrix(
                      (num_samples, data_row.shape[1]),
                      dtype=data_row.dtype,
                  )
              else:
                  indexes = np.tile(non_zero_indexes, num_samples)
                  indptr = np.array(
                      range(
                          0,
                          len(non_zero_indexes) * (num_samples + 1),
                          len(non_zero_indexes),
                      )
                  )
                  data_1d_shape = data.shape[0] * data.shape[1]
                  data_1d = data.reshape(data_1d_shape)
                  data = sp.sparse.csr_matrix(
                      (data_1d, indexes, indptr),
                      shape=(num_samples, data_row.shape[1]),
                  )
          categorical_features = self.categorical_features
          first_row = data_row
      else:
          first_row = self.discretizer.discretize(data_row)
      data[0] = data_row.copy()
      inverse = data.copy()
      for column in categorical_features:
          values = self.feature_values[column]
          freqs = self.feature_frequencies[column]
          inverse_column = self.random_state.choice(
              values, size=num_samples, replace=True, p=freqs
          )
          binary_column = (inverse_column == first_row[column]).astype(
              int
          )
          binary_column[0] = 1
          inverse_column[0] = data[0, column]
          data[:, column] = binary_column
          inverse[:, column] = inverse_column
      if self.discretizer is not None:
          inverse[1:] = self.discretizer.undiscretize(inverse[1:])
      inverse[0] = data_row
      return data, inverse
  
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 5 for calling the LimeTabularExplainer obj's underlying member method code with example usage: obj.__data_inverse(data_row, num_samples, sampling_method) and returns: data,  inverse