class_docstr: A basic collaborative filtering algorithm taking into account a
  *baseline* rating.
  
  
  The prediction :math:`\hat{r}_{ui}` is set as:
  
  .. math::
      \hat{r}_{ui} = b_{ui} + \frac{ \sum\limits_{v \in N^k_i(u)}
      \text{sim}(u, v) \cdot (r_{vi} - b_{vi})} {\sum\limits_{v \in
      N^k_i(u)} \text{sim}(u, v)}
  
  or
  
  
  .. math::
      \hat{r}_{ui} = b_{ui} + \frac{ \sum\limits_{j \in N^k_u(i)}
      \text{sim}(i, j) \cdot (r_{uj} - b_{uj})} {\sum\limits_{j \in
      N^k_u(i)} \text{sim}(i, j)}
  
  depending on the ``user_based`` field of the ``sim_options`` parameter. For
  the best predictions, use the :func:`pearson_baseline
  <surprise.similarities.pearson_baseline>` similarity measure.
  
  This algorithm corresponds to formula (3), section 2.2 of
  :cite:`Koren:2010`.
  
  Args:
      k(int): The (max) number of neighbors to take into account for
          aggregation (see :ref:`this note <actual_k_note>`). Default is
          ``40``.
      min_k(int): The minimum number of neighbors to take into account for
          aggregation. If there are not enough neighbors, the neighbor
          aggregation is set to zero (so the prediction ends up being
          equivalent to the baseline). Default is ``1``.
      sim_options(dict): A dictionary of options for the similarity
          measure. See :ref:`similarity_measures_configuration` for accepted
          options. It is recommended to use the :func:`pearson_baseline
          <surprise.similarities.pearson_baseline>` similarity measure.
  
      bsl_options(dict): A dictionary of options for the baseline estimates
          computation. See :ref:`baseline_estimates_configuration` for
          accepted options.
      verbose(bool): Whether to print trace messages of bias estimation,
          similarity, etc.  Default is True.
class_docstr_tok: ["A","basic","collaborative","filtering","algorithm","taking","into","account","a","*","baseline","*","rating",".","The","prediction",":","math",":","`","\\hat","{","r","}","_","{","ui","}","`","is","set","as",":","..","math",":",":","\\hat","{","r","}","_","{","ui","}","=","b_","{","ui","}","+","\\frac","{","\\sum\\limits_","{","v","\\in","N^k_i","(","u",")","}","\\text","{","sim","}","(","u",",","v",")","\\cdot","(","r_","{","vi","}","-","b_","{","vi","}",")","}","{","\\sum\\limits_","{","v","\\in","N^k_i","(","u",")","}","\\text","{","sim","}","(","u",",","v",")","}","or","..","math",":",":","\\hat","{","r","}","_","{","ui","}","=","b_","{","ui","}","+","\\frac","{","\\sum\\limits_","{","j","\\in","N^k_u","(","i",")","}","\\text","{","sim","}","(","i",",","j",")","\\cdot","(","r_","{","uj","}","-","b_","{","uj","}",")","}","{","\\sum\\limits_","{","j","\\in","N^k_u","(","i",")","}","\\text","{","sim","}","(","i",",","j",")","}","depending","on","the","``","user_based","``","field","of","the","``","sim_options","``","parameter",".","For","the","best","predictions",",","use","the",":","func",":","`","pearson_baseline","<","surprise.similarities.pearson_baseline",">","`","similarity","measure",".","This","algorithm","corresponds","to","formula","(","3",")",",","section","2.2","of",":","cite",":","`","Koren:2010","`",".","Args",":","k","(","int",")",":","The","(","max",")","number","of","neighbors","to","take","into","account","for","aggregation","(","see",":","ref",":","`","this","note","<","actual_k_note",">","`",")",".","Default","is","``","40","``",".","min_k","(","int",")",":","The","minimum","number","of","neighbors","to","take","into","account","for","aggregation",".","If","there","are","not","enough","neighbors",",","the","neighbor","aggregation","is","set","to","zero","(","so","the","prediction","ends","up","being","equivalent","to","the","baseline",")",".","Default","is","``","1","``",".","sim_options","(","dict",")",":","A","dictionary","of","options","for","the","similarity","measure",".","See",":","ref",":","`","similarity_measures_configuration","`","for","accepted","options",".","It","is","recommended","to","use","the",":","func",":","`","pearson_baseline","<","surprise.similarities.pearson_baseline",">","`","similarity","measure",".","bsl_options","(","dict",")",":","A","dictionary","of","options","for","the","baseline","estimates","computation",".","See",":","ref",":","`","baseline_estimates_configuration","`","for","accepted","options",".","verbose","(","bool",")",":","Whether","to","print","trace","messages","of","bias","estimation",",","similarity",",","etc",".","Default","is","True","."]
code: def __init__(
      self,
      k=40,
      min_k=1,
      sim_options={},
      bsl_options={},
      verbose=True,
      **kwargs,
  ):
      SymmetricAlgo.__init__(
          self,
          sim_options=sim_options,
          bsl_options=bsl_options,
          verbose=verbose,
          **kwargs,
      )
  
      self.k = k
      self.min_k = min_k
  
imports: import heapq
  import numpy
  from .algo_base import AlgoBase
  from .predictions import PredictionImpossible
label_desc: Use image node_id 1 to create a new KNNBaseline object from inherited base classes: SymmetricAlgo with example: obj = KNNBaseline(k, min_k, sim_options, bsl_options, verbose)