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: Build the similarity matrix.
  
  The way the similarity matrix is computed depends on the
  ``sim_options`` parameter passed at the creation of the algorithm (see
  :ref:`similarity_measures_configuration`).
  
  This method is only relevant for algorithms using a similarity measure,
  such as the :ref:`k-NN algorithms <pred_package_knn_inpired>`.
  
  Returns:
      The similarity matrix.
docstr_tok: ["Build","the","similarity","matrix",".","The","way","the","similarity","matrix","is","computed","depends","on","the","``","sim_options","``","parameter","passed","at","the","creation","of","the","algorithm","(","see",":","ref",":","`","similarity_measures_configuration","`",")",".","This","method","is","only","relevant","for","algorithms","using","a","similarity","measure",",","such","as","the",":","ref",":","`","k-NN","algorithms","<","pred_package_knn_inpired",">","`",".","Returns",":","The","similarity","matrix","."]
code: def compute_similarities(self):
      """Build the similarity matrix.
  
      The way the similarity matrix is computed depends on the
      ``sim_options`` parameter passed at the creation of the algorithm (see
      :ref:`similarity_measures_configuration`).
  
      This method is only relevant for algorithms using a similarity measure,
      such as the :ref:`k-NN algorithms <pred_package_knn_inpired>`.
  
      Returns:
          The similarity matrix."""
  
      construction_func = {
          "cosine": sims.cosine,
          "msd": sims.msd,
          "pearson": sims.pearson,
          "pearson_baseline": sims.pearson_baseline,
      }
  
      if self.sim_options["user_based"]:
          n_x, yr = self.trainset.n_users, self.trainset.ir
      else:
          n_x, yr = self.trainset.n_items, self.trainset.ur
  
      min_support = self.sim_options.get("min_support", 1)
  
      args = [n_x, yr, min_support]
  
      name = self.sim_options.get("name", "msd").lower()
      if name == "pearson_baseline":
          shrinkage = self.sim_options.get("shrinkage", 100)
          bu, bi = self.compute_baselines()
          if self.sim_options["user_based"]:
              bx, by = bu, bi
          else:
              bx, by = bi, bu
  
          args += [self.trainset.global_mean, bx, by, shrinkage]
  
      try:
          if getattr(self, "verbose", False):
              print(f"Computing the {name} similarity matrix...")
          sim = construction_func[name](*args)
          if getattr(self, "verbose", False):
              print("Done computing similarity matrix.")
          return sim
      except KeyError:
          raise NameError(
              "Wrong sim name "
              + name
              + ". Allowed values "
              + "are "
              + ", ".join(construction_func.keys())
              + "."
          )
  
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 7 for calling the AlgoBase obj's underlying member method code with example usage: obj.compute_similarities() and returns: sim