code: def compute_all_metrics(
      fcst_df: pd.DataFrame,
      ts_id_colnames: List[str],
      metric_names: Optional[List[set]] = None,
  ):
      """
      Calculate metrics per grain.
  
      :param fcst_df: forecast data frame. Must contain 2 columns: 'actual_level' and 'predicted_level'
      :param metric_names: (optional) the list of metric names to return
      :param ts_id_colnames: (optional) list of grain column names
      :return: dictionary of summary table for all tests and final decision on stationary vs nonstaionary
      """
      if not metric_names:
          metric_names = list(constants.Metric.SCALAR_REGRESSION_SET)
  
      if ts_id_colnames is None:
          ts_id_colnames = []
  
      metrics_list = []
      if ts_id_colnames:
          for grain, df in fcst_df.groupby(ts_id_colnames):
              one_grain_metrics_df = _compute_metrics(df, metric_names)
              one_grain_metrics_df[GRAIN] = _format_grain_name(grain)
              metrics_list.append(one_grain_metrics_df)
  
      # overall metrics
      one_grain_metrics_df = _compute_metrics(fcst_df, metric_names)
      one_grain_metrics_df[GRAIN] = ALL_GRAINS
      metrics_list.append(one_grain_metrics_df)
  
      # collect into a data frame
      return pd.concat(metrics_list)
  
file_path: MachineLearningNotebooks/how-to-use-azureml/automated-machine-learning/forecasting-backtest-single-model/assets/score.py
imports: from typing import Any, Dict, Optional, List
  import argparse
  import json
  import os
  import re
  import numpy
  import pandas
  from matplotlib import pyplot
  from matplotlib.backends.backend_pdf import PdfPages
  from azureml.automl.core.shared import constants
  from azureml.automl.core.shared.types import GrainType
  from azureml.automl.runtime.shared.score import scoring
label_desc: Use image node_id 3 for calling a global function with example usage: compute_all_metrics(fcst_df, ts_id_colnames, metric_names) and returns: pd