class_docstr: Class for computing metrics based on a single
  :obj:`~aif360.datasets.BinaryLabelDataset`.
class_docstr_tok: ["Class","for","computing","metrics","based","on","a","single",":","obj",":","`","~aif360.datasets.BinaryLabelDataset","`","."]
docstr: Individual fairness metric from [1]_ that measures how similar the
  labels are for similar instances.
  
  .. math::
     1 - \frac{1}{n}\sum_{i=1}^n |\hat{y}_i -
     \frac{1}{\text{n_neighbors}} \sum_{j\in\mathcal{N}_{\text{n_neighbors}}(x_i)} \hat{y}_j|
  
  Args:
      n_neighbors (int, optional): Number of neighbors for the knn
          computation.
  
  References:
      .. [1] R. Zemel, Y. Wu, K. Swersky, T. Pitassi, and C. Dwork,
         "Learning Fair Representations,"
         International Conference on Machine Learning, 2013.
docstr_tok: ["Individual","fairness","metric","from","[","1","]","_","that","measures","how","similar","the","labels","are","for","similar","instances",".","..","math",":",":","1","-","\\frac","{","1","}","{","n","}","\\sum_","{","i=1","}","^n","|\\hat","{","y","}","_i","-","\\frac","{","1","}","{","\\text","{","n_neighbors","}","}","\\sum_","{","j\\in\\mathcal","{","N","}","_","{","\\text","{","n_neighbors","}","}","(","x_i",")","}","\\hat","{","y","}","_j|","Args",":","n_neighbors","(","int",",","optional",")",":","Number","of","neighbors","for","the","knn","computation",".","References",":","..","[","1","]","R.","Zemel",",","Y.","Wu",",","K.","Swersky",",","T.","Pitassi",",","and","C.","Dwork",",","``","Learning","Fair","Representations",",","''","International","Conference","on","Machine","Learning",",","2013","."]
code: def consistency(self, n_neighbors=5):
      r"""Individual fairness metric from [1]_ that measures how similar the
      labels are for similar instances.
  
      .. math::
         1 - \frac{1}{n}\sum_{i=1}^n |\hat{y}_i -
         \frac{1}{\text{n_neighbors}} \sum_{j\in\mathcal{N}_{\text{n_neighbors}}(x_i)} \hat{y}_j|
  
      Args:
          n_neighbors (int, optional): Number of neighbors for the knn
              computation.
  
      References:
          .. [1] R. Zemel, Y. Wu, K. Swersky, T. Pitassi, and C. Dwork,
             "Learning Fair Representations,"
             International Conference on Machine Learning, 2013.
      """
  
      X = self.dataset.features
      num_samples = X.shape[0]
      y = self.dataset.labels
  
      # learn a KNN on the features
      nbrs = NearestNeighbors(
          n_neighbors=n_neighbors, algorithm="ball_tree"
      )
      nbrs.fit(X)
      _, indices = nbrs.kneighbors(X)
  
      # compute consistency score
      consistency = 0.0
      for i in range(num_samples):
          consistency += np.abs(y[i] - np.mean(y[indices[i]]))
      consistency = 1.0 - consistency / num_samples
  
      return consistency
  
imports: import numpy
  from sklearn.neighbors import NearestNeighbors
  from aif360.algorithms.inprocessing.gerryfair.auditor import Auditor
  from aif360.datasets import BinaryLabelDataset
  from aif360.datasets.multiclass_label_dataset import MulticlassLabelDataset
  from aif360.metrics import DatasetMetric, utils
  from aif360.algorithms.inprocessing.gerryfair.clean import *
label_desc: Use image node_id 7 for calling the BinaryLabelDatasetMetric obj's underlying member method code with example usage: obj.consistency(n_neighbors) and returns: consistency