code: def test_metric_hierarchical(multioutput, multilevel, n_columns):
      """Test hierarchical input for metrics."""
      # create numpy weights based on n_columns
      if multioutput == "numpy":
          if n_columns == 1:
              return None
          multioutput = np.random.rand(n_columns)
  
      # create test data
      y_pred = _make_hierarchical(random_state=21, n_columns=n_columns)
      y_true = _make_hierarchical(random_state=42, n_columns=n_columns)
  
      metric = MeanSquaredError(
          multioutput=multioutput, multilevel=multilevel
      )
  
      res = metric(
          y_true=y_true,
          y_pred=y_pred,
      )
  
      if multilevel == "raw_values":
          assert isinstance(res, (pd.DataFrame, pd.Series))
          assert isinstance(res.index, pd.MultiIndex)
  
          expected_index = y_true.index.droplevel(-1).unique()
          found_index = res.index.unique()
          assert set(expected_index) == set(found_index)
          if isinstance(multioutput, str):
              if multioutput == "raw_values" and isinstance(
                  res, pd.DataFrame
              ):
                  assert all(y_true.columns == res.columns)
      # if multilevel == "uniform_average" or "uniform_average_time"
      else:
          if (
              isinstance(multioutput, np.ndarray)
              or multioutput == "uniform_average"
          ):
              assert isinstance(res, float)
          elif multioutput == "raw_values":
              assert isinstance(res, np.ndarray)
              assert res.ndim == 1
              assert len(res) == len(y_true.columns)
  
file_path: sktime/sktime/performance_metrics/tests/test_metrics_classes.py
imports: from inspect import getmembers, isclass
  import numpy
  import pandas
  import pytest
  from sktime.datasets import load_airline
  from sktime.performance_metrics.forecasting import MeanSquaredError, _classes, make_forecasting_scorer
  from sktime.utils._testing.hierarchical import _make_hierarchical
  from sktime.utils._testing.panel import _make_panel
  from sktime.utils._testing.series import _make_series
label_desc: Use image node_id 2 for calling a global function with example usage: test_metric_hierarchical(multioutput, multilevel, n_columns) and returns: None