code: def h2o_r2_score(y_actual, y_predicted, weights=1.0):
      """
      R-squared (coefficient of determination) regression score function
  
      :param y_actual: H2OFrame of actual response.
      :param y_predicted: H2OFrame of predicted response.
      :param weights: (Optional) sample weights.
      :returns: R-squared (best is 1.0, lower is worse).
      """
      ModelBase._check_targets(y_actual, y_predicted)
      numerator = (
          (weights * (y_actual - y_predicted) ** 2).sum().flatten()
      )
      denominator = (
          (weights * (y_actual - _colmean(y_actual)) ** 2)
          .sum()
          .flatten()
      )
  
      if denominator == 0.0:
          return 1.0 if numerator == 0.0 else 0.0  # 0/0 => 1, else 0
      return 1 - numerator / denominator
  
file_path: h2o-3/h2o-py/h2o/model/models/regression.py
imports: from h2o.exceptions import H2OValueError
  from h2o.model import ModelBase
  from h2o.model.extensions import has_extension
  from h2o.utils.compatibility import *
  from h2o.utils.shared_utils import _colmean
  from h2o.utils.typechecks import assert_is_type
label_desc: Use image node_id 6 for calling a global function with example usage: h2o_r2_score(y_actual, y_predicted, weights) and returns: unknown, unknown