class_docstr: Computes R2 score.
  
  Formula:
  
  ```python
  sum_squares_residuals = sum((y_true - y_pred) ** 2)
  sum_squares = sum((y_true - mean(y_true)) ** 2)
  R2 = 1 - sum_squares_residuals / sum_squares
  ```
  
  This is also called the
  [coefficient of determination](
  https://en.wikipedia.org/wiki/Coefficient_of_determination).
  
  It indicates how close the fitted regression line
  is to ground-truth data.
  
  - The highest score possible is 1.0. It indicates that the predictors
      perfectly accounts for variation in the target.
  - A score of 0.0 indicates that the predictors do not
      account for variation in the target.
  - It can also be negative if the model is worse than random.
  
  This metric can also compute the "Adjusted R2" score.
  
  Args:
      class_aggregation: Specifies how to aggregate scores corresponding to
          different output classes (or target dimensions),
          i.e. different dimensions on the last axis of the predictions.
          Equivalent to `multioutput` argument in Scikit-Learn.
          Should be one of
          `None` (no aggregation), `"uniform_average"`,
          `"variance_weighted_average"`.
      num_regressors: Number of independent regressors used
          ("Adjusted R2" score). 0 is the standard R2 score.
          Defaults to `0`.
      name: Optional. string name of the metric instance.
      dtype: Optional. data type of the metric result.
  
  Example:
  
  >>> y_true = np.array([[1], [4], [3]], dtype=np.float32)
  >>> y_pred = np.array([[2], [4], [4]], dtype=np.float32)
  >>> metric = keras.metrics.R2Score()
  >>> metric.update_state(y_true, y_pred)
  >>> result = metric.result()
  >>> result
  0.57142854
class_docstr_tok: ["Computes","R2","score",".","Formula",":","``","`","python","sum_squares_residuals","=","sum","(","(","y_true","-","y_pred",")","*","*","2",")","sum_squares","=","sum","(","(","y_true","-","mean","(","y_true",")",")","*","*","2",")","R2","=","1","-","sum_squares_residuals","\/","sum_squares","``","`","This","is","also","called","the","[","coefficient","of","determination","]","(","https",":","\/\/en.wikipedia.org\/wiki\/Coefficient_of_determination",")",".","It","indicates","how","close","the","fitted","regression","line","is","to","ground-truth","data",".","-","The","highest","score","possible","is","1.0",".","It","indicates","that","the","predictors","perfectly","accounts","for","variation","in","the","target",".","-","A","score","of","0.0","indicates","that","the","predictors","do","not","account","for","variation","in","the","target",".","-","It","can","also","be","negative","if","the","model","is","worse","than","random",".","This","metric","can","also","compute","the","``","Adjusted","R2","''","score",".","Args",":","class_aggregation",":","Specifies","how","to","aggregate","scores","corresponding","to","different","output","classes","(","or","target","dimensions",")",",","i.e",".","different","dimensions","on","the","last","axis","of","the","predictions",".","Equivalent","to","`","multioutput","`","argument","in","Scikit-Learn",".","Should","be","one","of","`","None","`","(","no","aggregation",")",",","`","``","uniform_average","''","`",",","`","``","variance_weighted_average","''","`",".","num_regressors",":","Number","of","independent","regressors","used","(","``","Adjusted","R2","''","score",")",".","0","is","the","standard","R2","score",".","Defaults","to","`","0","`",".","name",":","Optional",".","string","name","of","the","metric","instance",".","dtype",":","Optional",".","data","type","of","the","metric","result",".","Example",":",">",">",">","y_true","=","np.array","(","[","[","1","]",",","[","4","]",",","[","3","]","]",",","dtype=np.float32",")",">",">",">","y_pred","=","np.array","(","[","[","2","]",",","[","4","]",",","[","4","]","]",",","dtype=np.float32",")",">",">",">","metric","=","keras.metrics.R2Score","(",")",">",">",">","metric.update_state","(","y_true",",","y_pred",")",">",">",">","result","=","metric.result","(",")",">",">",">","result","0.57142854"]
code: def result(self):
      mean = self.sum / self.count
      total = self.squared_sum - self.sum * mean
      raw_scores = 1 - (self.total_mse / total)
      raw_scores = ops.where(ops.isinf(raw_scores), 0.0, raw_scores)
  
      if self.class_aggregation == "uniform_average":
          r2_score = ops.mean(raw_scores)
      elif self.class_aggregation == "variance_weighted_average":
          weighted_sum = ops.sum(total * raw_scores)
          sum_of_weights = ops.sum(total)
          r2_score = weighted_sum / sum_of_weights
      else:
          r2_score = raw_scores
  
      if self.num_regressors != 0:
          if self.num_regressors > self.num_samples - 1:
              warnings.warn(
                  "More independent predictors than datapoints "
                  "in adjusted R2 score. Falling back to standard R2 score.",
                  stacklevel=2,
              )
          elif self.num_regressors == self.num_samples - 1:
              warnings.warn(
                  "Division by zero in Adjusted R2 score. "
                  "Falling back to standard R2 score.",
                  stacklevel=2,
              )
          else:
              n = ops.convert_to_tensor(
                  self.num_samples, dtype="float32"
              )
              p = ops.convert_to_tensor(
                  self.num_regressors, dtype="float32"
              )
              num = ops.multiply(
                  ops.subtract(1.0, r2_score), ops.subtract(n, 1.0)
              )
              den = ops.subtract(ops.subtract(n, p), 1.0)
              r2_score = ops.subtract(1.0, ops.divide(num, den))
      return r2_score
  
imports: import warnings
  from keras import initializers
  from keras import ops
  from keras.api_export import keras_export
  from keras.losses.loss import squeeze_to_same_rank
  from keras.losses.losses import log_cosh
  from keras.losses.losses import mean_absolute_error
  from keras.losses.losses import mean_absolute_percentage_error
  from keras.losses.losses import mean_squared_error
  from keras.losses.losses import mean_squared_logarithmic_error
  from keras.metrics import reduction_metrics
  from keras.utils.numerical_utils import normalize
label_desc: Use image node_id 4 for calling the R2Score obj's underlying member method code with example usage: obj.result() and returns: r2_score