class_docstr: Spark Rating Evaluator
class_docstr_tok: ["Spark","Rating","Evaluator"]
docstr: Calculate explained variance.
  
  .. note::
     Spark MLLib's implementation is buggy (can lead to values > 1), hence we use var().
  
  Returns:
      float: Explained variance (min=0, max=1).
docstr_tok: ["Calculate","explained","variance",".","..","note",":",":","Spark","MLLib","'s","implementation","is","buggy","(","can","lead","to","values",">","1",")",",","hence","we","use","var","(",")",".","Returns",":","float",":","Explained","variance","(","min=0",",","max=1",")","."]
code: def exp_var(self):
      """Calculate explained variance.
  
      .. note::
         Spark MLLib's implementation is buggy (can lead to values > 1), hence we use var().
  
      Returns:
          float: Explained variance (min=0, max=1).
      """
      var1 = self.y_pred_true.selectExpr(
          "variance(label-prediction)"
      ).collect()[0][0]
      var2 = self.y_pred_true.selectExpr("variance(label)").collect()[
          0
      ][0]
  
      if var1 is None or var2 is None:
          return -np.inf
      else:
          # numpy divide is more tolerant to var2 being zero
          return 1 - np.divide(var1, var2)
  
imports: import numpy
  from recommenders.utils.constants import DEFAULT_PREDICTION_COL, DEFAULT_USER_COL, DEFAULT_ITEM_COL, DEFAULT_RATING_COL, DEFAULT_RELEVANCE_COL, DEFAULT_SIMILARITY_COL, DEFAULT_ITEM_FEATURES_COL, DEFAULT_ITEM_SIM_MEASURE, DEFAULT_TIMESTAMP_COL, DEFAULT_K, DEFAULT_THRESHOLD
label_desc: Use image node_id 5 for calling the SparkRatingEvaluation obj's underlying member method code with example usage: obj.exp_var() and returns: unknown, unknown