code: def test_rolling_r2():
      def tail(iterable, n):
          return collections.deque(iterable, maxlen=n)
  
      r2 = utils.Rolling(metrics.R2(), window_size=3)
      n = r2.window_size
      sk_r2 = sk_metrics.r2_score
      y_true = [
          0.4656520648923188,
          0.5768996330715701,
          0.045385529424484594,
          0.31852843450357393,
          0.8344133739124894,
      ]
      y_pred = [
          0.5431172475992199,
          0.2436885541729249,
          0.20238076597257637,
          0.6173775443360237,
          0.9194776501054074,
      ]
  
      for i, (yt, yp) in enumerate(zip(y_true, y_pred)):
          r2.update(yt, yp)
  
          if i >= 2:
              assert math.isclose(
                  r2.get(),
                  sk_r2(
                      tail(y_true[: i + 1], n), tail(y_pred[: i + 1], n)
                  ),
              )
  
imports: from __future__ import annotations
  import collections
  import math
  from sklearn import metrics
  from river import metrics, utils
label_desc: Use image node_id 2 for calling a global function with example usage: test_rolling_r2() and returns: collections