code: def test_forecast_metric(self):
      n_samples = 50
      y_true = np.arange(n_samples) + 1
      y_pred = y_true + 1
  
      assert_almost_equal(
          Evaluator.evaluate("mse", y_true, y_pred, aggregate="mean")[
              0
          ],
          1.0,
      )
      assert_almost_equal(
          Evaluator.evaluate("mae", y_true, y_pred, aggregate="mean")[
              0
          ],
          1.0,
      )
      assert_almost_equal(
          Evaluator.evaluate("r2", y_true, y_pred, aggregate="mean")[0],
          0.995,
          2,
      )
      assert_almost_equal(
          Evaluator.evaluate("smape", y_true, y_pred, aggregate="mean")[
              0
          ],
          3.895,
          3,
      )
      # 3-dim r2
      assert_almost_equal(
          Evaluator.evaluate(
              "r2",
              y_true.reshape(5, 5, 2),
              y_pred.reshape(5, 5, 2),
              aggregate="mean",
          )[0],
          0.995,
          2,
      )
      # 2-dim r2
      assert_almost_equal(
          np.mean(
              Evaluator.evaluate(
                  "r2",
                  y_true.reshape(25, 2),
                  y_pred.reshape(25, 2),
                  aggregate=None,
              )[0]
          ),
          0.995,
          2,
      )
  
      y_true = np.array([3, -0.5, 2, 7])
      y_pred = np.array([2.5, -0.3, 2, 8])
  
      assert_almost_equal(
          Evaluator.evaluate("mape", y_true, y_pred, aggregate="mean")[
              0
          ],
          17.74 / 100,
          2,
      )
      assert_almost_equal(
          Evaluator.evaluate("RMSE", y_true, y_pred, aggregate="mean")[
              0
          ],
          0.57,
          2,
      )
  
file_path: BigDL/python/chronos/test/bigdl/chronos/metric/test_forecast_metrics.py
imports: import numpy
  import pytest
  import time
  from unittest import TestCase
  from numpy.testing import assert_almost_equal
  from numpy.testing import assert_array_almost_equal
  from bigdl.chronos.metric.forecast_metrics import Evaluator
  from ..None import op_torch, op_tf2, op_distributed, op_diff_set_all
label_desc: Use image node_id 3 for calling the TestChronosForecastMetrics obj's underlying member method code with example usage: obj.test_forecast_metric() without return types