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: Compute the rating prediction for given user and item.
  
  The ``predict`` method converts raw ids to inner ids and then calls the
  ``estimate`` method which is defined in every derived class. If the
  prediction is impossible (e.g. because the user and/or the item is
  unknown), the prediction is set according to
  :meth:`default_prediction()
  <surprise.prediction_algorithms.algo_base.AlgoBase.default_prediction>`.
  
  Args:
      uid: (Raw) id of the user. See :ref:`this note<raw_inner_note>`.
      iid: (Raw) id of the item. See :ref:`this note<raw_inner_note>`.
      r_ui(float): The true rating :math:`r_{ui}`. Optional, default is
          ``None``.
      clip(bool): Whether to clip the estimation into the rating scale.
          For example, if :math:`\hat{r}_{ui}` is :math:`5.5` while the
          rating scale is :math:`[1, 5]`, then :math:`\hat{r}_{ui}` is
          set to :math:`5`. Same goes if :math:`\hat{r}_{ui} < 1`.
          Default is ``True``.
      verbose(bool): Whether to print details of the prediction.  Default
          is False.
  
  Returns:
      A :obj:`Prediction            <surprise.prediction_algorithms.predictions.Prediction>` object
      containing:
  
      - The (raw) user id ``uid``.
      - The (raw) item id ``iid``.
      - The true rating ``r_ui`` (:math:`r_{ui}`).
      - The estimated rating (:math:`\hat{r}_{ui}`).
      - Some additional details about the prediction that might be useful
        for later analysis.
docstr_tok: ["Compute","the","rating","prediction","for","given","user","and","item",".","The","``","predict","``","method","converts","raw","ids","to","inner","ids","and","then","calls","the","``","estimate","``","method","which","is","defined","in","every","derived","class",".","If","the","prediction","is","impossible","(","e.g",".","because","the","user","and\/or","the","item","is","unknown",")",",","the","prediction","is","set","according","to",":","meth",":","`","default_prediction","(",")","<","surprise.prediction_algorithms.algo_base.AlgoBase.default_prediction",">","`",".","Args",":","uid",":","(","Raw",")","id","of","the","user",".","See",":","ref",":","`","this","note","<","raw_inner_note",">","`",".","iid",":","(","Raw",")","id","of","the","item",".","See",":","ref",":","`","this","note","<","raw_inner_note",">","`",".","r_ui","(","float",")",":","The","true","rating",":","math",":","`","r_","{","ui","}","`",".","Optional",",","default","is","``","None","``",".","clip","(","bool",")",":","Whether","to","clip","the","estimation","into","the","rating","scale",".","For","example",",","if",":","math",":","`","\\hat","{","r","}","_","{","ui","}","`","is",":","math",":","`","5.5","`","while","the","rating","scale","is",":","math",":","`","[","1",",","5","]","`",",","then",":","math",":","`","\\hat","{","r","}","_","{","ui","}","`","is","set","to",":","math",":","`","5","`",".","Same","goes","if",":","math",":","`","\\hat","{","r","}","_","{","ui","}","<","1","`",".","Default","is","``","True","``",".","verbose","(","bool",")",":","Whether","to","print","details","of","the","prediction",".","Default","is","False",".","Returns",":","A",":","obj",":","`","Prediction","<","surprise.prediction_algorithms.predictions.Prediction",">","`","object","containing",":","-","The","(","raw",")","user","id","``","uid","``",".","-","The","(","raw",")","item","id","``","iid","``",".","-","The","true","rating","``","r_ui","``","(",":","math",":","`","r_","{","ui","}","`",")",".","-","The","estimated","rating","(",":","math",":","`","\\hat","{","r","}","_","{","ui","}","`",")",".","-","Some","additional","details","about","the","prediction","that","might","be","useful","for","later","analysis","."]
code: def predict(self, uid, iid, r_ui=None, clip=True, verbose=False):
      """Compute the rating prediction for given user and item.
  
          The ``predict`` method converts raw ids to inner ids and then calls the
          ``estimate`` method which is defined in every derived class. If the
          prediction is impossible (e.g. because the user and/or the item is
          unknown), the prediction is set according to
          :meth:`default_prediction()
          <surprise.prediction_algorithms.algo_base.AlgoBase.default_prediction>`.
  
          Args:
              uid: (Raw) id of the user. See :ref:`this note<raw_inner_note>`.
              iid: (Raw) id of the item. See :ref:`this note<raw_inner_note>`.
              r_ui(float): The true rating :math:`r_{ui}`. Optional, default is
                  ``None``.
              clip(bool): Whether to clip the estimation into the rating scale.
                  For example, if :math:`\\hat{r}_{ui}` is :math:`5.5` while the
                  rating scale is :math:`[1, 5]`, then :math:`\\hat{r}_{ui}` is
                  set to :math:`5`. Same goes if :math:`\\hat{r}_{ui} < 1`.
                  Default is ``True``.
              verbose(bool): Whether to print details of the prediction.  Default
                  is False.
  
          Returns:
              A :obj:`Prediction\
              <surprise.prediction_algorithms.predictions.Prediction>` object
              containing:
  
              - The (raw) user id ``uid``.
              - The (raw) item id ``iid``.
              - The true rating ``r_ui`` (:math:`r_{ui}`).
              - The estimated rating (:math:`\\hat{r}_{ui}`).
              - Some additional details about the prediction that might be useful
                for later analysis.
          """
  
      # Convert raw ids to inner ids
      try:
          iuid = self.trainset.to_inner_uid(uid)
      except ValueError:
          iuid = "UKN__" + str(uid)
      try:
          iiid = self.trainset.to_inner_iid(iid)
      except ValueError:
          iiid = "UKN__" + str(iid)
  
      details = {}
      try:
          est = self.estimate(iuid, iiid)
  
          # If the details dict was also returned
          if isinstance(est, tuple):
              est, details = est
  
          details["was_impossible"] = False
  
      except PredictionImpossible as e:
          est = self.default_prediction()
          details["was_impossible"] = True
          details["reason"] = str(e)
  
      # clip estimate into [lower_bound, higher_bound]
      if clip:
          lower_bound, higher_bound = self.trainset.rating_scale
          est = min(higher_bound, est)
          est = max(lower_bound, est)
  
      pred = Prediction(uid, iid, r_ui, est, details)
  
      if verbose:
          print(pred)
  
      return pred
  
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 3 for calling the AlgoBase obj's underlying member method code with example usage: obj.predict(uid, iid, r_ui, clip, verbose) and returns: pred