code: def run_test(
      env: TrainEnv,
      predictor: Predictor,
      test_dataset: Dataset,
      hyperparameters: dict,
  ) -> None:
      len_original = maybe_len(test_dataset)
  
      test_dataset = FilterTransformation(
          lambda x: x["target"].shape[-1] > predictor.prediction_length
      ).apply(test_dataset)
  
      len_filtered = len(test_dataset)
  
      if len_original is not None and len_original > len_filtered:
          logger.warning(
              "Not all time series in the test-channel have "
              "enough data to be used for evaluation. Proceeding with "
              f"{len_filtered}/{len_original} "
              f"(~{int(len_filtered / len_original * 100)}%) items."
          )
  
      forecast_it, ts_it = backtest.make_evaluation_predictions(
          dataset=test_dataset, predictor=predictor, num_samples=100
      )
  
      test_quantiles = (
          [
              Quantile.parse(quantile).name
              for quantile in hyperparameters["test_quantiles"]
          ]
          if "test_quantiles" in hyperparameters
          else None
      )
  
      if test_quantiles is not None:
          logger.info(
              f"Using quantiles `{test_quantiles}` for evaluation."
          )
          evaluator = Evaluator(quantiles=test_quantiles)
      else:
          evaluator = Evaluator()
  
      agg_metrics, item_metrics = evaluator(
          ts_iterator=ts_it,
          fcst_iterator=forecast_it,
          num_series=len(test_dataset),
      )
  
      # we only log aggregate metrics for now as item metrics may be very large
      for name, score in agg_metrics.items():
          logger.info(
              f"#test_score ({env.current_host}, {name}): {score}"
          )
  
      # store metrics
      with open(
          env.path.model / "agg_metrics.json", "w"
      ) as agg_metric_file:
          json.dump(agg_metrics, agg_metric_file)
      with open(
          env.path.model / "item_metrics.csv", "w"
      ) as item_metrics_file:
          item_metrics.to_csv(item_metrics_file, index=False)
  
file_path: gluonts/src/gluonts/shell/train.py
imports: import json
  import logging
  from typing import Any, Optional, Type, Union
  import gluonts
  from gluonts.core import fqname_for
  from gluonts.dataset.common import Dataset
  from gluonts.evaluation import Evaluator, backtest
  from gluonts.model.estimator import Estimator, IncrementallyTrainable
  from gluonts.model.forecast import Quantile
  from gluonts.model.predictor import Predictor
  from gluonts.itertools import maybe_len
  from gluonts.transform import FilterTransformation
  from .env import TrainEnv
  from .util import invoke_with
label_desc: Use image node_id 5 for calling a global function with example usage: run_test(env, predictor, test_dataset, hyperparameters) without return types