code: def evaluate(dataset_name, estimator):
      dataset = get_dataset(dataset_name)
      estimator = estimator(
          prediction_length=dataset.metadata.prediction_length,
          freq=dataset.metadata.freq,
          use_feat_static_cat=True,
          cardinality=[
              feat_static_cat.cardinality
              for feat_static_cat in dataset.metadata.feat_static_cat
          ],
          trainer=Trainer(
              epochs=epochs,
              num_batches_per_epoch=num_batches_per_epoch,
          ),
      )
  
      print(f"evaluating {estimator} on {dataset}")
  
      predictor = estimator.train(dataset.train)
  
      forecast_it, ts_it = make_evaluation_predictions(
          dataset.test, predictor=predictor, num_samples=100
      )
  
      agg_metrics, item_metrics = Evaluator()(
          ts_it, forecast_it, num_series=len(dataset.test)
      )
  
      pprint.pprint(agg_metrics)
  
      eval_dict = agg_metrics
      eval_dict["dataset"] = dataset_name
      eval_dict["estimator"] = type(estimator).__name__
      return eval_dict
  
file_path: gluonts/examples/benchmark_m4.py
imports: import pprint
  from functools import partial
  import pandas
  from gluonts.dataset.repository import get_dataset
  from gluonts.mx.distribution.piecewise_linear import PiecewiseLinearOutput
  from gluonts.evaluation import make_evaluation_predictions, Evaluator
  from gluonts.mx import DeepAREstimator
  from gluonts.mx import MQCNNEstimator
  from gluonts.mx.trainer import Trainer
label_desc: Use image node_id 1 for calling a global function with example usage: evaluate(dataset_name, estimator) and returns: eval_dict