class_docstr: Abstract class where is defined the basic behavior of a prediction
  algorithm.
  
  Keyword Args:
      baseline_options(dict, optional): If the algorithm needs to compute a
          baseline estimate, the ``baseline_options`` parameter is used to
          configure how they are computed. See
          :ref:`baseline_estimates_configuration` for usage.
class_docstr_tok: ["Abstract","class","where","is","defined","the","basic","behavior","of","a","prediction","algorithm",".","Keyword","Args",":","baseline_options","(","dict",",","optional",")",":","If","the","algorithm","needs","to","compute","a","baseline","estimate",",","the","``","baseline_options","``","parameter","is","used","to","configure","how","they","are","computed",".","See",":","ref",":","`","baseline_estimates_configuration","`","for","usage","."]
docstr: Return the ``k`` nearest neighbors of ``iid``, which is the inner id
  of a user or an item, depending on the ``user_based`` field of
  ``sim_options`` (see :ref:`similarity_measures_configuration`).
  
  As the similarities are computed on the basis of a similarity measure,
  this method is only relevant for algorithms using a similarity measure,
  such as the :ref:`k-NN algorithms <pred_package_knn_inpired>`.
  
  For a usage example, see the :ref:`FAQ <get_k_nearest_neighbors>`.
  
  Args:
      iid(int): The (inner) id of the user (or item) for which we want
          the nearest neighbors. See :ref:`this note<raw_inner_note>`.
  
      k(int): The number of neighbors to retrieve.
  
  Returns:
      The list of the ``k`` (inner) ids of the closest users (or items)
      to ``iid``.
docstr_tok: ["Return","the","``","k","``","nearest","neighbors","of","``","iid","``",",","which","is","the","inner","id","of","a","user","or","an","item",",","depending","on","the","``","user_based","``","field","of","``","sim_options","``","(","see",":","ref",":","`","similarity_measures_configuration","`",")",".","As","the","similarities","are","computed","on","the","basis","of","a","similarity","measure",",","this","method","is","only","relevant","for","algorithms","using","a","similarity","measure",",","such","as","the",":","ref",":","`","k-NN","algorithms","<","pred_package_knn_inpired",">","`",".","For","a","usage","example",",","see","the",":","ref",":","`","FAQ","<","get_k_nearest_neighbors",">","`",".","Args",":","iid","(","int",")",":","The","(","inner",")","id","of","the","user","(","or","item",")","for","which","we","want","the","nearest","neighbors",".","See",":","ref",":","`","this","note","<","raw_inner_note",">","`",".","k","(","int",")",":","The","number","of","neighbors","to","retrieve",".","Returns",":","The","list","of","the","``","k","``","(","inner",")","ids","of","the","closest","users","(","or","items",")","to","``","iid","``","."]
code: def get_neighbors(self, iid, k):
      """Return the ``k`` nearest neighbors of ``iid``, which is the inner id
      of a user or an item, depending on the ``user_based`` field of
      ``sim_options`` (see :ref:`similarity_measures_configuration`).
  
      As the similarities are computed on the basis of a similarity measure,
      this method is only relevant for algorithms using a similarity measure,
      such as the :ref:`k-NN algorithms <pred_package_knn_inpired>`.
  
      For a usage example, see the :ref:`FAQ <get_k_nearest_neighbors>`.
  
      Args:
          iid(int): The (inner) id of the user (or item) for which we want
              the nearest neighbors. See :ref:`this note<raw_inner_note>`.
  
          k(int): The number of neighbors to retrieve.
  
      Returns:
          The list of the ``k`` (inner) ids of the closest users (or items)
          to ``iid``.
      """
  
      if self.sim_options["user_based"]:
          all_instances = self.trainset.all_users
      else:
          all_instances = self.trainset.all_items
      others = [
          (x, self.sim[iid, x]) for x in all_instances() if x != iid
      ]
      others = heapq.nlargest(k, others, key=lambda tple: tple[1])
      k_nearest_neighbors = [j for (j, _) in others]
  
      return k_nearest_neighbors
  
file_path: Surprise/surprise/prediction_algorithms/algo_base.py
imports: import heapq
  from ..None import similarities
  from .optimize_baselines import baseline_als, baseline_sgd
  from .predictions import Prediction, PredictionImpossible
label_desc: Use image node_id 8 for calling the AlgoBase obj's underlying member method code with example usage: obj.get_neighbors(iid, k) and returns: k_nearest_neighbors