You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: r2_score.rb
    path of file: ./repos/rumale/rumale-evaluation_measure/lib/rumale/evaluation_measure
    
    the code of the file until where you have to start completion: # frozen_string_literal: t
    
      def initialize; end

      # Calculate the coefficient of determination.
      #
      # @param y_true [Numo::DFloat] (shape: [n_samples, n_outputs]) Ground truth target values.
      # @param y_pred [Numo::DFloat] (shape: [n_samples, n_outputs]) Estimated taget values.
      # @return [Float] Coefficient of determination
      def score(y_true, y_pred)
        n_samples, n_outputs = y_true.shape
        numerator = ((y_true - y_pred)**2).sum(axis: 0)
        yt_mean = y_true.sum(axis: 0) / n_samples
        denominator = ((y_true - yt_mean)**2).sum(axis: 0)
        if n_outputs.nil?
          denominator.zero? ? 0.0 : 1.0 - numerator / denominator
        else
          scores = 1 - numerator / denominator
          scores[denominator.eq(0)] = 0.0
          scores.sum / scores.size
        end
      end