code: def test_integration_r2_score():
      np.random.seed(1)
      size = 105
      np_y_pred = np.random.rand(size, 1)
      np_y = np.random.rand(size, 1)
      np.random.shuffle(np_y)
  
      batch_size = 15
  
      def update_fn(engine, batch):
          idx = (engine.state.iteration - 1) * batch_size
          y_true_batch = np_y[idx : idx + batch_size]
          y_pred_batch = np_y_pred[idx : idx + batch_size]
          return torch.from_numpy(y_pred_batch), torch.from_numpy(
              y_true_batch
          )
  
      engine = Engine(update_fn)
  
      m = R2Score()
      m.attach(engine, "r2_score")
  
      data = list(range(size // batch_size))
      r_squared = engine.run(data, max_epochs=1).metrics["r2_score"]
  
      assert r2_score(np_y, np_y_pred) == pytest.approx(r_squared)
  
imports: import os
  import numpy
  import pytest
  import torch
  from sklearn.metrics import r2_score
  import ignite.distributed
  from ignite.contrib.metrics.regression import R2Score
  from ignite.engine import Engine
  from ignite.exceptions import NotComputableError
label_desc: Use image node_id 5 for calling a global function with example usage: test_integration_r2_score() and returns: torch,  torch