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: NearestNeighborContrastiveExplainer initialization.
  
  Args:
      model (Callable): Classification Model which will be used for contrastive
          explanation.
      n_classes (int): Number of classes the classification produces.
      metric (str): Distance metric for neighborhood finding. This metric is used
          to find neighborhood in the embedding space. The implementation internally
          uses Scipy KDTree for neighborhood search. See the documentation of
          scipy.spatial.distance and the metrics listed in distance_metrics for more
          information. Defaults to euclidean.
      neighbors (int): Number of neighbors to fetch for producing the explanation.
          The NearestNeighborContrastiveExplainer uses these neighbors to produce
          explanation. In order to understand the variety in the neighborhood profile,
          higher value is suggested for this parameter, which impacts the size of the
          explanation produced. For fast greedy explanation lower value is suggested
          for this parameter. Defaults to 3.
      embedding_type (Union[str, EmbeddingType]): This parameter controls the nature of
          the embedding produced. It can be set to supervised (EmbeddingType.SUPERVISED)
          or unsupervised (EmbeddingType.UNSUPERVISED). The unsupervised embedding ensures
          data distribution compliance, while supervised embedding allow imposing further
          structural constraints to the embedding by provided business tags during the model
          fit step. Defaults to EmbeddingType.UNSUPERVISED.
      embedding_dim (int): Dimension of the produced embedding. Lower dimension allows faster
          search, while at the cost of lossy reconstruction. An appropriate emebedding_dim
          selection depends of the data complexity and available data. Defaults to 8.
      category_enc_dim (int): Autoencoder handles categorical variable as embedding/one hot
          encoding. This parameter defines the internal dimension to be used by the auto-encoder
          to derive the categorical embedding. Defaults to 3.
      category_encoding (str): Strategy specification for categorical variable handling.
          Supported values are 'ohe' (One hot encoding) and 'label' (Uses embedding).
          Defaults to "ohe".
      numeric_scaling (str): Data scaling to be used on numeric columns for computational
          stability. This uses global scaling, i.e., applied uniformly over the entire training
          batch for all numeric columns. Supported values are minmax, standard, quantile.
          Defaults to None.
      layers_config (List[int]): This is auto-encoder internals specification. Autoencoder
          uses MLP layers to derive the embedding, this parameter specifies number of hidden
          layers in the embedding, and their respective dimensions. Defaults to [16, 16].
      encoder_activation (str): Activation function used by the auto-encoder encoding layers.
          Supports all activation function as enabled by tensorflow framework. Defaults to "relu".
      decoder_activation (str): Activation function used by the auto-encoder decoding layers.
          Support all activation functions as supported by the tensorflow framework. Defaults to
          "relu".
      embedding_activation (str): This is embedding layer activation, this can be separately
          specified than hidden layer activation. Support all tensorflow activation function.
          Defaults to "tanh".
      encoder_kernel_regularizer (str): Regularization for the encoder MLP kernel. Regularization
          results in stable prediction model. Defaults to "l1".
      encoder_kernel_initializer (str): Initialization algorithm for the MLP kernel. Defaults to
          "glorot_uniform".
      encoder_bias_initializer (str): Initialization algorithm for the MLP bias. Defaults to "zeros".
      encoder_activity_regularizer (str): Encoder activity regularizer for MLP layers. Defaults to
          None.
      decoder_kernel_regularizer (str): Kernel regularizer for the decoder MLP layer. All tensorflow
          regularizer algorithm are supported. Defaults to "l1".
      decoder_kernel_initializer (str): Decoder MLP kernel weight initializer algorithm. All
          tensorflow initializer algorithms are supported. Defaults to "glorot_uniform".
      decoder_bias_initializer (str): Decoder MLP bias initializer algorithm. All tensorflow
          initializer algorithms are supported. Defaults to "zeros".
      decoder_activity_regularizer (str): Decoder activity regularization algorithm. All tensorflow
          regularizer algorithms are supported. Defaults to None.
      decoder_last_layer_activation (str): Decoder last layer activation. This layer produces the
          input reconstruction. Supports all tensorflow supported activation function. Defaults
          to "linear".
      embedding_activity_regularizer (str): Embedding activity regularization method. Uses default
          tensorflow framework, support all activity regularizer algorithm. Defaults to None.
      classifier_layers (List[int]): Supervised auto-encoder uses classification layer for the
          structural constraint on the embedding. MLP layer for this classification task. This
          specifies the dimension of the MLP layer for this classification task. Defaults to [16].
      classifier_activation (str): Supervised auto-encoder uses classification layer for
          the structural constraint on the embedding. For supervised auto-encoder activation
          of MLP layer classification layer. Defaults to "relu".
      classifier_kernel_regularizer (str): Supervised auto-encoder uses classification layer for
          the structural constraint on the embedding. This parameter describes the kernel
          regularization for supervised auto-encoder MLP layer for classification. Defaults to None.
      classifier_kernel_initilizer (str): Supervised auto-encoder uses classification layer for the
          structural constraint on the embedding. This parameter describes the kernel initialization
          algorithm for supervised auto-encoder MLP layer for the classification. Defaults to
          "glorot_uniform".
      classifier_bias_initializer (str): Describes the MLP bias initialization algorithm, for the
          classification layer of supervised auto-encoder. Defaults to "zeros".
docstr_tok: ["NearestNeighborContrastiveExplainer","initialization",".","Args",":","model","(","Callable",")",":","Classification","Model","which","will","be","used","for","contrastive","explanation",".","n_classes","(","int",")",":","Number","of","classes","the","classification","produces",".","metric","(","str",")",":","Distance","metric","for","neighborhood","finding",".","This","metric","is","used","to","find","neighborhood","in","the","embedding","space",".","The","implementation","internally","uses","Scipy","KDTree","for","neighborhood","search",".","See","the","documentation","of","scipy.spatial.distance","and","the","metrics","listed","in","distance_metrics","for","more","information",".","Defaults","to","euclidean",".","neighbors","(","int",")",":","Number","of","neighbors","to","fetch","for","producing","the","explanation",".","The","NearestNeighborContrastiveExplainer","uses","these","neighbors","to","produce","explanation",".","In","order","to","understand","the","variety","in","the","neighborhood","profile",",","higher","value","is","suggested","for","this","parameter",",","which","impacts","the","size","of","the","explanation","produced",".","For","fast","greedy","explanation","lower","value","is","suggested","for","this","parameter",".","Defaults","to","3.","embedding_type","(","Union","[","str",",","EmbeddingType","]",")",":","This","parameter","controls","the","nature","of","the","embedding","produced",".","It","can","be","set","to","supervised","(","EmbeddingType.SUPERVISED",")","or","unsupervised","(","EmbeddingType.UNSUPERVISED",")",".","The","unsupervised","embedding","ensures","data","distribution","compliance",",","while","supervised","embedding","allow","imposing","further","structural","constraints","to","the","embedding","by","provided","business","tags","during","the","model","fit","step",".","Defaults","to","EmbeddingType.UNSUPERVISED",".","embedding_dim","(","int",")",":","Dimension","of","the","produced","embedding",".","Lower","dimension","allows","faster","search",",","while","at","the","cost","of","lossy","reconstruction",".","An","appropriate","emebedding_dim","selection","depends","of","the","data","complexity","and","available","data",".","Defaults","to","8.","category_enc_dim","(","int",")",":","Autoencoder","handles","categorical","variable","as","embedding\/one","hot","encoding",".","This","parameter","defines","the","internal","dimension","to","be","used","by","the","auto-encoder","to","derive","the","categorical","embedding",".","Defaults","to","3.","category_encoding","(","str",")",":","Strategy","specification","for","categorical","variable","handling",".","Supported","values","are","'ohe","'","(","One","hot","encoding",")","and","'label","'","(","Uses","embedding",")",".","Defaults","to","``","ohe","''",".","numeric_scaling","(","str",")",":","Data","scaling","to","be","used","on","numeric","columns","for","computational","stability",".","This","uses","global","scaling",",","i.e.",",","applied","uniformly","over","the","entire","training","batch","for","all","numeric","columns",".","Supported","values","are","minmax",",","standard",",","quantile",".","Defaults","to","None",".","layers_config","(","List","[","int","]",")",":","This","is","auto-encoder","internals","specification",".","Autoencoder","uses","MLP","layers","to","derive","the","embedding",",","this","parameter","specifies","number","of","hidden","layers","in","the","embedding",",","and","their","respective","dimensions",".","Defaults","to","[","16",",","16","]",".","encoder_activation","(","str",")",":","Activation","function","used","by","the","auto-encoder","encoding","layers",".","Supports","all","activation","function","as","enabled","by","tensorflow","framework",".","Defaults","to","``","relu","''",".","decoder_activation","(","str",")",":","Activation","function","used","by","the","auto-encoder","decoding","layers",".","Support","all","activation","functions","as","supported","by","the","tensorflow","framework",".","Defaults","to","``","relu","''",".","embedding_activation","(","str",")",":","This","is","embedding","layer","activation",",","this","can","be","separately","specified","than","hidden","layer","activation",".","Support","all","tensorflow","activation","function",".","Defaults","to","``","tanh","''",".","encoder_kernel_regularizer","(","str",")",":","Regularization","for","the","encoder","MLP","kernel",".","Regularization","results","in","stable","prediction","model",".","Defaults","to","``","l1","''",".","encoder_kernel_initializer","(","str",")",":","Initialization","algorithm","for","the","MLP","kernel",".","Defaults","to","``","glorot_uniform","''",".","encoder_bias_initializer","(","str",")",":","Initialization","algorithm","for","the","MLP","bias",".","Defaults","to","``","zeros","''",".","encoder_activity_regularizer","(","str",")",":","Encoder","activity","regularizer","for","MLP","layers",".","Defaults","to","None",".","decoder_kernel_regularizer","(","str",")",":","Kernel","regularizer","for","the","decoder","MLP","layer",".","All","tensorflow","regularizer","algorithm","are","supported",".","Defaults","to","``","l1","''",".","decoder_kernel_initializer","(","str",")",":","Decoder","MLP","kernel","weight","initializer","algorithm",".","All","tensorflow","initializer","algorithms","are","supported",".","Defaults","to","``","glorot_uniform","''",".","decoder_bias_initializer","(","str",")",":","Decoder","MLP","bias","initializer","algorithm",".","All","tensorflow","initializer","algorithms","are","supported",".","Defaults","to","``","zeros","''",".","decoder_activity_regularizer","(","str",")",":","Decoder","activity","regularization","algorithm",".","All","tensorflow","regularizer","algorithms","are","supported",".","Defaults","to","None",".","decoder_last_layer_activation","(","str",")",":","Decoder","last","layer","activation",".","This","layer","produces","the","input","reconstruction",".","Supports","all","tensorflow","supported","activation","function",".","Defaults","to","``","linear","''",".","embedding_activity_regularizer","(","str",")",":","Embedding","activity","regularization","method",".","Uses","default","tensorflow","framework",",","support","all","activity","regularizer","algorithm",".","Defaults","to","None",".","classifier_layers","(","List","[","int","]",")",":","Supervised","auto-encoder","uses","classification","layer","for","the","structural","constraint","on","the","embedding",".","MLP","layer","for","this","classification","task",".","This","specifies","the","dimension","of","the","MLP","layer","for","this","classification","task",".","Defaults","to","[","16","]",".","classifier_activation","(","str",")",":","Supervised","auto-encoder","uses","classification","layer","for","the","structural","constraint","on","the","embedding",".","For","supervised","auto-encoder","activation","of","MLP","layer","classification","layer",".","Defaults","to","``","relu","''",".","classifier_kernel_regularizer","(","str",")",":","Supervised","auto-encoder","uses","classification","layer","for","the","structural","constraint","on","the","embedding",".","This","parameter","describes","the","kernel","regularization","for","supervised","auto-encoder","MLP","layer","for","classification",".","Defaults","to","None",".","classifier_kernel_initilizer","(","str",")",":","Supervised","auto-encoder","uses","classification","layer","for","the","structural","constraint","on","the","embedding",".","This","parameter","describes","the","kernel","initialization","algorithm","for","supervised","auto-encoder","MLP","layer","for","the","classification",".","Defaults","to","``","glorot_uniform","''",".","classifier_bias_initializer","(","str",")",":","Describes","the","MLP","bias","initialization","algorithm",",","for","the","classification","layer","of","supervised","auto-encoder",".","Defaults","to","``","zeros","''","."]
code: def __init__(
      self,
      model: Callable = None,
      n_classes: int = 2,
      metric: str = "euclidean",  # TODO
      neighbors: int = 3,
      embedding_type: Union[
          str, EmbeddingType
      ] = EmbeddingType.UNSUPERVISED,
      embedding_dim: int = 8,
      category_enc_dim: int = 3,
      category_encoding: str = "ohe",  # supported values ohe|label
      numeric_scaling: str = None,  # supported values minmax|standard|quantile
      layers_config: List[int] = [16, 16],
      encoder_activation: str = "relu",
      decoder_activation: str = "relu",
      embedding_activation: str = "tanh",
      encoder_kernel_regularizer: str = "l1",
      encoder_kernel_initializer: str = "glorot_uniform",
      encoder_bias_initializer: str = "zeros",
      encoder_activity_regularizer: str = None,
      decoder_kernel_regularizer: str = "l1",
      decoder_kernel_initializer: str = "glorot_uniform",
      decoder_bias_initializer: str = "zeros",
      decoder_activity_regularizer: str = None,
      decoder_last_layer_activation: str = "linear",
      embedding_activity_regularizer: str = None,
      classifier_layers: List[int] = [16],
      classifier_activation: str = "relu",
      classifier_kernel_regularizer: str = None,
      classifier_kernel_initilizer: str = "glorot_uniform",
      classifier_bias_initializer: str = "zeros",
  ):
      """
      NearestNeighborContrastiveExplainer initialization.
  
      Args:
          model (Callable): Classification Model which will be used for contrastive
              explanation.
          n_classes (int): Number of classes the classification produces.
          metric (str): Distance metric for neighborhood finding. This metric is used
              to find neighborhood in the embedding space. The implementation internally
              uses Scipy KDTree for neighborhood search. See the documentation of
              scipy.spatial.distance and the metrics listed in distance_metrics for more
              information. Defaults to euclidean.
          neighbors (int): Number of neighbors to fetch for producing the explanation.
              The NearestNeighborContrastiveExplainer uses these neighbors to produce
              explanation. In order to understand the variety in the neighborhood profile,
              higher value is suggested for this parameter, which impacts the size of the
              explanation produced. For fast greedy explanation lower value is suggested
              for this parameter. Defaults to 3.
          embedding_type (Union[str, EmbeddingType]): This parameter controls the nature of
              the embedding produced. It can be set to supervised (EmbeddingType.SUPERVISED)
              or unsupervised (EmbeddingType.UNSUPERVISED). The unsupervised embedding ensures
              data distribution compliance, while supervised embedding allow imposing further
              structural constraints to the embedding by provided business tags during the model
              fit step. Defaults to EmbeddingType.UNSUPERVISED.
          embedding_dim (int): Dimension of the produced embedding. Lower dimension allows faster
              search, while at the cost of lossy reconstruction. An appropriate emebedding_dim
              selection depends of the data complexity and available data. Defaults to 8.
          category_enc_dim (int): Autoencoder handles categorical variable as embedding/one hot
              encoding. This parameter defines the internal dimension to be used by the auto-encoder
              to derive the categorical embedding. Defaults to 3.
          category_encoding (str): Strategy specification for categorical variable handling.
              Supported values are 'ohe' (One hot encoding) and 'label' (Uses embedding).
              Defaults to "ohe".
          numeric_scaling (str): Data scaling to be used on numeric columns for computational
              stability. This uses global scaling, i.e., applied uniformly over the entire training
              batch for all numeric columns. Supported values are minmax, standard, quantile.
              Defaults to None.
          layers_config (List[int]): This is auto-encoder internals specification. Autoencoder
              uses MLP layers to derive the embedding, this parameter specifies number of hidden
              layers in the embedding, and their respective dimensions. Defaults to [16, 16].
          encoder_activation (str): Activation function used by the auto-encoder encoding layers.
              Supports all activation function as enabled by tensorflow framework. Defaults to "relu".
          decoder_activation (str): Activation function used by the auto-encoder decoding layers.
              Support all activation functions as supported by the tensorflow framework. Defaults to
              "relu".
          embedding_activation (str): This is embedding layer activation, this can be separately
              specified than hidden layer activation. Support all tensorflow activation function.
              Defaults to "tanh".
          encoder_kernel_regularizer (str): Regularization for the encoder MLP kernel. Regularization
              results in stable prediction model. Defaults to "l1".
          encoder_kernel_initializer (str): Initialization algorithm for the MLP kernel. Defaults to
              "glorot_uniform".
          encoder_bias_initializer (str): Initialization algorithm for the MLP bias. Defaults to "zeros".
          encoder_activity_regularizer (str): Encoder activity regularizer for MLP layers. Defaults to
              None.
          decoder_kernel_regularizer (str): Kernel regularizer for the decoder MLP layer. All tensorflow
              regularizer algorithm are supported. Defaults to "l1".
          decoder_kernel_initializer (str): Decoder MLP kernel weight initializer algorithm. All
              tensorflow initializer algorithms are supported. Defaults to "glorot_uniform".
          decoder_bias_initializer (str): Decoder MLP bias initializer algorithm. All tensorflow
              initializer algorithms are supported. Defaults to "zeros".
          decoder_activity_regularizer (str): Decoder activity regularization algorithm. All tensorflow
              regularizer algorithms are supported. Defaults to None.
          decoder_last_layer_activation (str): Decoder last layer activation. This layer produces the
              input reconstruction. Supports all tensorflow supported activation function. Defaults
              to "linear".
          embedding_activity_regularizer (str): Embedding activity regularization method. Uses default
              tensorflow framework, support all activity regularizer algorithm. Defaults to None.
          classifier_layers (List[int]): Supervised auto-encoder uses classification layer for the
              structural constraint on the embedding. MLP layer for this classification task. This
              specifies the dimension of the MLP layer for this classification task. Defaults to [16].
          classifier_activation (str): Supervised auto-encoder uses classification layer for
              the structural constraint on the embedding. For supervised auto-encoder activation
              of MLP layer classification layer. Defaults to "relu".
          classifier_kernel_regularizer (str): Supervised auto-encoder uses classification layer for
              the structural constraint on the embedding. This parameter describes the kernel
              regularization for supervised auto-encoder MLP layer for classification. Defaults to None.
          classifier_kernel_initilizer (str): Supervised auto-encoder uses classification layer for the
              structural constraint on the embedding. This parameter describes the kernel initialization
              algorithm for supervised auto-encoder MLP layer for the classification. Defaults to
              "glorot_uniform".
          classifier_bias_initializer (str): Describes the MLP bias initialization algorithm, for the
              classification layer of supervised auto-encoder. Defaults to "zeros".
      """
      super(NearestNeighborContrastiveExplainer, self).__init__()
      self._config = dict(
          model=model,
          n_classes=n_classes,
          metric=metric,
          neighbors=neighbors,
          embedding_type=embedding_type.name
          if isinstance(embedding_type, EmbeddingType)
          else embedding_type,
          embedding_dim=embedding_dim,
          category_enc_dim=category_enc_dim,
          category_encoding=category_encoding,
          numeric_scaling=numeric_scaling,
          layers_config=layers_config,
          encoder_activation=encoder_activation,
          decoder_activation=decoder_activation,
          embedding_activation=embedding_activation,
          encoder_kernel_regularizer=encoder_kernel_regularizer,
          encoder_kernel_initializer=encoder_kernel_initializer,
          encoder_bias_initializer=encoder_bias_initializer,
          encoder_activity_regularizer=encoder_activity_regularizer,
          decoder_kernel_initializer=decoder_kernel_initializer,
          decoder_kernel_regularizer=decoder_kernel_regularizer,
          decoder_bias_initializer=decoder_bias_initializer,
          decoder_activity_regularizer=decoder_activity_regularizer,
          decoder_last_layer_activation=decoder_last_layer_activation,
          embedding_activity_regularizer=embedding_activity_regularizer,
          classifier_layers=classifier_layers,
          classifier_activation=classifier_activation,
          classifier_kernel_regularizer=classifier_kernel_regularizer,
          classifier_kernel_initilizer=classifier_kernel_initilizer,
          classifier_bias_initializer=classifier_bias_initializer,
      )
      self._embedding = None
      self._exemplar = None
      self._neighbor_tree = None
      self._class_based_neighbor = dict()
      self.is_fitted = False
  
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 1 to create a new NearestNeighborContrastiveExplainer object from inherited base classes: LocalBBExplainer with example: obj = NearestNeighborContrastiveExplainer(model, n_classes, metric, neighbors, embedding_type, embedding_dim, category_enc_dim, category_encoding, numeric_scaling, layers_config, encoder_activation, decoder_activation, embedding_activation, encoder_kernel_regularizer, encoder_kernel_initializer, encoder_bias_initializer, encoder_activity_regularizer, decoder_kernel_regularizer, decoder_kernel_initializer, decoder_bias_initializer, decoder_activity_regularizer, decoder_last_layer_activation, embedding_activity_regularizer, classifier_layers, classifier_activation, classifier_kernel_regularizer, classifier_kernel_initilizer, classifier_bias_initializer)