code: def median_squared_percentage_error(
      y_true,
      y_pred,
      horizon_weight=None,
      multioutput="uniform_average",
      square_root=False,
      symmetric=False,
      **kwargs,
  ):
      """Median squared percentage error (MdSPE)  or square root version.
  
      If `square_root` is False then calculates MdSPE and if `square_root` is True
      then calculates root median squared percentage error (RMdSPE). If `symmetric`
      is True then calculates sMdSPE or sRMdSPE. Output is non-negative floating
      point. The best value is 0.0.
  
      MdSPE is measured in squared percentage error relative to the test data.
      RMdSPE is measured in percentage error relative to the test data.
      Because the calculation takes the square rather than absolute value of
      the percentage forecast error, large errors are penalized more than
      MAPE, sMAPE, MdAPE or sMdAPE.
  
      Taking the median instead of the mean of the absolute percentage errors also
      makes this metric more robust to error outliers since the median tends
      to be a more robust measure of central tendency in the presence of outliers.
  
      There is no limit on how large the error can be, particulalrly when `y_true`
      values are close to zero. In such cases the function returns a large value
      instead of `inf`.
  
      Parameters
      ----------
      y_true : pd.Series, pd.DataFrame or np.array of shape (fh,) or (fh, n_outputs) \
               where fh is the forecasting horizon
          Ground truth (correct) target values.
  
      y_pred : pd.Series, pd.DataFrame or np.array of shape (fh,) or (fh, n_outputs) \
               where fh is the forecasting horizon
          Forecasted values.
  
      horizon_weight : array-like of shape (fh,), default=None
          Forecast horizon weights.
  
      multioutput : {'raw_values', 'uniform_average'}  or array-like of shape \
              (n_outputs,), default='uniform_average'
          Defines how to aggregate metric for multivariate (multioutput) data.
          If array-like, values used as weights to average the errors.
          If 'raw_values', returns a full set of errors in case of multioutput input.
          If 'uniform_average', errors of all outputs are averaged with uniform weight.
  
      square_root : bool, default=False
          Whether to take the square root of the mean squared error.
          If True, returns root mean squared error (RMSPE)
          If False, returns mean squared error (MSPE)
  
      symmetric : bool, default=False
          Calculates symmetric version of metric if True.
  
      Returns
      -------
      loss : float
          MdSPE or RMdSPE loss.
          If multioutput is 'raw_values', then MdSPE or RMdSPE is returned for each
          output separately.
          If multioutput is 'uniform_average' or an ndarray of weights, then the
          weighted average MdSPE or RMdSPE of all output errors is returned.
  
      See Also
      --------
      mean_absolute_percentage_error
      median_absolute_percentage_error
      mean_squared_percentage_error
  
      References
      ----------
      Hyndman, R. J and Koehler, A. B. (2006). "Another look at measures of
      forecast accuracy", International Journal of Forecasting, Volume 22, Issue 4.
  
      Examples
      --------
      >>> from sktime.performance_metrics.forecasting import \
          median_squared_percentage_error
      >>> y_true = np.array([3, -0.5, 2, 7, 2])
      >>> y_pred = np.array([2.5, 0.0, 2, 8, 1.25])
      >>> median_squared_percentage_error(y_true, y_pred, symmetric=False)
      0.027777777777777776
      >>> median_squared_percentage_error(y_true, y_pred, square_root=True, \
      symmetric=False)
      0.16666666666666666
      >>> y_true = np.array([[0.5, 1], [-1, 1], [7, -6]])
      >>> y_pred = np.array([[0, 2], [-1, 2], [8, -5]])
      >>> median_squared_percentage_error(y_true, y_pred, symmetric=False)
      0.5102040816326531
      >>> median_squared_percentage_error(y_true, y_pred, square_root=True, \
      symmetric=False)
      0.5714285714285714
      >>> median_squared_percentage_error(y_true, y_pred, multioutput='raw_values', \
      symmetric=False)
      array([0.02040816, 1.        ])
      >>> median_squared_percentage_error(y_true, y_pred, multioutput='raw_values', \
      square_root=True, symmetric=False)
      array([0.14285714, 1.        ])
      >>> median_squared_percentage_error(y_true, y_pred, multioutput=[0.3, 0.7], \
      symmetric=False)
      0.7061224489795918
      >>> median_squared_percentage_error(y_true, y_pred, multioutput=[0.3, 0.7], \
      square_root=True, symmetric=False)
      0.7428571428571428
      """
      _, y_true, y_pred, multioutput = _check_reg_targets(
          y_true, y_pred, multioutput
      )
      perc_err = _percentage_error(y_true, y_pred, symmetric=symmetric)
      if horizon_weight is None:
          output_errors = np.median(np.square(perc_err), axis=0)
      else:
          check_consistent_length(y_true, horizon_weight)
          output_errors = _weighted_percentile(
              np.square(perc_err),
              sample_weight=horizon_weight,
          )
  
      if square_root:
          output_errors = np.sqrt(output_errors)
  
      if isinstance(multioutput, str):
          if multioutput == "raw_values":
              return output_errors
          elif multioutput == "uniform_average":
              # pass None as weights to np.average: uniform mean
              multioutput = None
  
      return np.average(output_errors, weights=multioutput)
  
imports: import numpy
  from scipy.stats import gmean
  from sklearn.metrics import mean_absolute_error
  from sklearn.metrics import mean_squared_error
  from sklearn.metrics import median_absolute_error
  from sklearn.metrics._regression import _check_reg_targets
  from sklearn.utils.stats import _weighted_percentile
  from sklearn.utils.validation import check_consistent_length
  from sktime.utils.stats import _weighted_geometric_mean
label_desc: Use image node_id 17 for calling a global function with example usage: median_squared_percentage_error(y_true, y_pred, horizon_weight, multioutput, square_root, symmetric) and returns: np, output_errors