code: def test_metric_output_by_instance(metric, multioutput, n_columns):
      """Test output of evaluate_by_index is of correct type, dependent on multioutput."""
      # 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_series(
          n_columns=n_columns, n_timepoints=20, random_state=21
      )
      y_true = _make_series(
          n_columns=n_columns, n_timepoints=20, random_state=42
      )
  
      # coerce to DataFrame since _make_series does not return consistent output type
      y_pred = pd.DataFrame(y_pred)
      y_true = pd.DataFrame(y_true)
  
      res = metric(multioutput=multioutput).evaluate_by_index(
          y_true=y_true,
          y_pred=y_pred,
          y_pred_benchmark=y_pred,
          y_train=y_true,
      )
  
      if isinstance(multioutput, str) and multioutput == "raw_values":
          assert isinstance(res, pd.DataFrame)
          assert (res.columns == y_true.columns).all()
      else:
          assert isinstance(res, pd.Series)
  
      assert (res.index == y_true.index).all()
  
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 4 for calling a global function with example usage: test_metric_output_by_instance(metric, multioutput, n_columns) and returns: None