code: def _get_weights(regressor):
      # tree-based models from sklearn which have feature importance values
      if hasattr(regressor, "feature_importances_"):
          weights = regressor.feature_importances_
      # linear regression models from sklearn which have coefficient values
      elif hasattr(regressor, "coef_"):
          weights = regressor.coef_
      else:
          raise NotImplementedError(
              """The given regressor is not supported. It must have
              either an attribute feature_importances_ or coef_ after fitting."""
          )
      # avoid ZeroDivisionError if all weights are 0
      if weights.sum() == 0:
          weights += 1
      return list(weights)
  
imports: import numpy
  import pandas
  from scipy.stats import gmean
  from sklearn.pipeline import Pipeline
  from sktime.forecasting.base import ForecastingHorizon
  from sktime.forecasting.base._meta import _HeterogenousEnsembleForecaster
  from sktime.split import temporal_train_test_split
  from sktime.utils.stats import _weighted_geometric_mean, _weighted_max, _weighted_median, _weighted_min
  from sktime.utils.validation.forecasting import check_regressor
label_desc: Use image node_id 1 for calling a global function with example usage: _get_weights(regressor) and returns: list