class_docstr: The Nearest Neighbor (NN) Contrastive algorithm uses an auto-encoder to train low dimensional
  representation for each data point, for the nearest neighbor search. The dimensional reduction improves
  the reliability of the neighborhood search. Along with dimensionality reduction, the
  current implementation also allows for imposing class structure-driven orientation of the
  embedding space. For example, in a loan application, a high-income applicant and a
  low-income applicant may have very different evaluation criteria. The auto-encoder uses
  high-income and low-income tag classes during the auto-encoder training, ensuring
  instances with the same tags are in close neighborhoods.
  
  The implementation allows exemplar selection in two ways, (1) contrastive exemplar
  selection is guided by a model prediction, and (2) the user explicitly provides an
  exemplar with a different class tag than the query instance (model-free). Given a query
  instance, the resulting explanation is a set of nearest neighbor exemplars with different
  class tags than the query instances.
docstr: Fit the explainer.
  
  Args:
      x (pd.DataFrame): Training data.
      y (np.ndarray): If provided these data labels is used for training supervised
          auto-encoder. This labels need not be same as data target classes from target
          class label. Defaults to None.
      features (List[str]): Names of the features to be used. If not specified all the
          columns in the training data will be used as features. Defaults to None.
      categorical_features (List[str]): Names of the categorical features in the data.
          This must match the column names. Defaults to [].
      categorical_values (dict): Lookup dictionary for all categorical variables, list
          of possible categorical values. Defaults to {}.
      epochs (int): Number of epochs to be used for auto-encoder training. Defaults to 5.
      batch_size (int): Batch-size for the auto-encoder training. Should be smaller than
          the available data in training data. Defaults to 128.
      verbose (int): Log verbosity. Defaults to 0.
      shuffle (bool): Shuffle batch per epoch. Defaults to True.
      validation_fraction (float): Fraction specifying the validation split during encoder
          training. Defaults to 0.
      max_training_records (int): Maximum number of records to be used for the auto-encoder
          training. Enables explainer performance optimization. Defaults to 10000.
      exemplars (pd.DataFrame): Exemplar neighbors to be used to compute explanations. If
          None, training dataset will be used as exemplars. Defaults to None.
      random_seed (int): Random seed to fit auto encoder. Defaults to None
docstr_tok: ["Fit","the","explainer",".","Args",":","x","(","pd.DataFrame",")",":","Training","data",".","y","(","np.ndarray",")",":","If","provided","these","data","labels","is","used","for","training","supervised","auto-encoder",".","This","labels","need","not","be","same","as","data","target","classes","from","target","class","label",".","Defaults","to","None",".","features","(","List","[","str","]",")",":","Names","of","the","features","to","be","used",".","If","not","specified","all","the","columns","in","the","training","data","will","be","used","as","features",".","Defaults","to","None",".","categorical_features","(","List","[","str","]",")",":","Names","of","the","categorical","features","in","the","data",".","This","must","match","the","column","names",".","Defaults","to","[","]",".","categorical_values","(","dict",")",":","Lookup","dictionary","for","all","categorical","variables",",","list","of","possible","categorical","values",".","Defaults","to","{","}",".","epochs","(","int",")",":","Number","of","epochs","to","be","used","for","auto-encoder","training",".","Defaults","to","5.","batch_size","(","int",")",":","Batch-size","for","the","auto-encoder","training",".","Should","be","smaller","than","the","available","data","in","training","data",".","Defaults","to","128.","verbose","(","int",")",":","Log","verbosity",".","Defaults","to","0.","shuffle","(","bool",")",":","Shuffle","batch","per","epoch",".","Defaults","to","True",".","validation_fraction","(","float",")",":","Fraction","specifying","the","validation","split","during","encoder","training",".","Defaults","to","0.","max_training_records","(","int",")",":","Maximum","number","of","records","to","be","used","for","the","auto-encoder","training",".","Enables","explainer","performance","optimization",".","Defaults","to","10000.","exemplars","(","pd.DataFrame",")",":","Exemplar","neighbors","to","be","used","to","compute","explanations",".","If","None",",","training","dataset","will","be","used","as","exemplars",".","Defaults","to","None",".","random_seed","(","int",")",":","Random","seed","to","fit","auto","encoder",".","Defaults","to","None"]
code: def fit(
      self,
      x: pd.DataFrame,
      y: np.ndarray = None,
      features: List[str] = None,
      categorical_features: List[str] = [],
      categorical_values: dict = {},
      epochs: int = 5,
      batch_size: int = 128,
      verbose: int = 0,
      shuffle: bool = True,
      validation_fraction: float = 0,
      max_training_records: int = 10000,
      exemplars: pd.DataFrame = None,
      random_seed: int = None,
      **kwargs,
  ):
      """
      Fit the explainer.
  
      Args:
          x (pd.DataFrame): Training data.
          y (np.ndarray): If provided these data labels is used for training supervised
              auto-encoder. This labels need not be same as data target classes from target
              class label. Defaults to None.
          features (List[str]): Names of the features to be used. If not specified all the
              columns in the training data will be used as features. Defaults to None.
          categorical_features (List[str]): Names of the categorical features in the data.
              This must match the column names. Defaults to [].
          categorical_values (dict): Lookup dictionary for all categorical variables, list
              of possible categorical values. Defaults to {}.
          epochs (int): Number of epochs to be used for auto-encoder training. Defaults to 5.
          batch_size (int): Batch-size for the auto-encoder training. Should be smaller than
              the available data in training data. Defaults to 128.
          verbose (int): Log verbosity. Defaults to 0.
          shuffle (bool): Shuffle batch per epoch. Defaults to True.
          validation_fraction (float): Fraction specifying the validation split during encoder
              training. Defaults to 0.
          max_training_records (int): Maximum number of records to be used for the auto-encoder
              training. Enables explainer performance optimization. Defaults to 10000.
          exemplars (pd.DataFrame): Exemplar neighbors to be used to compute explanations. If
              None, training dataset will be used as exemplars. Defaults to None.
          random_seed (int): Random seed to fit auto encoder. Defaults to None
  
      """
      opts = self._embedding_args(**kwargs)
      cls = None
      if self.embedding_type == EmbeddingType.SUPERVISED.name:
          cls = JointAEEmbedding  # supervised
      else:
          cls = AEEmbedding  # unsupervised
  
      self._embedding = cls(
          data=x,
          features=features,
          categorical_features=categorical_features,
          categorical_values=categorical_values,
          max_train_records=max_training_records,
          **opts,
      )
      history = self._embedding.fit(
          x,
          y,
          epochs=epochs,
          shuffle=shuffle,
          verbose=verbose,
          batch_size=batch_size,
          validation_fraction=validation_fraction,
          random_seed=random_seed,
      )
      self.is_fitted = self._embedding.is_fitted
      if exemplars is None:
          exemplars = x
      self.set_exemplars(exemplars)
      return history
  
imports: from enum import Enum
  from typing import List, Union, Callable
  import numpy
  import pandas
  from sklearn.neighbors import KDTree
  from aix360.algorithms.lbbe import LocalBBExplainer
  from aix360.algorithms.nncontrastive.embedding import AEEmbedding, JointAEEmbedding
label_desc: Use image node_id 7 for calling the NearestNeighborContrastiveExplainer obj's underlying member method code with example usage: obj.fit(x, y, features, categorical_features, categorical_values, epochs, batch_size, verbose, shuffle, validation_fraction, max_training_records, exemplars, random_seed) and returns: history