code: def rescaled(cls):
      """
      Create regressors that rescale their predictions.
  
      This decorator creates regressors that store a min and a max for the training
      data and make sure that predictions fall within that range.  They also store
      the means and SDs of the gold standard and the predictions on the training
      set to rescale the predictions (e.g., as in e-rater).
  
      Parameters
      ----------
      cls : BaseEstimator
          An estimator class to add rescaling to.
  
      Returns
      -------
      cls : BaseEstimator
          Modified version of estimator class with rescaled functions added.
  
      Raises
      ------
      ValueError
          If classifier cannot be rescaled (i.e. is not a regressor).
      """
      # If this class has already been run through the decorator, return it
      if hasattr(cls, "rescale"):
          return cls
  
      # Save original versions of functions to use later.
      orig_init = cls.__init__
      orig_fit = cls.fit
      orig_predict = cls.predict
  
      if cls._estimator_type == "classifier":
          raise ValueError(
              "Classifiers cannot be rescaled. Only regressors " "can."
          )
  
      # Define all new versions of functions
      @wraps(cls.fit)
      def fit(self, X: np.ndarray, y=None):  # noqa: D417
          """
          Fit a model.
  
          Also store the mean, SD, max and min of the training set
          and the mean and SD of the predictions on the training set.
  
          Parameters
          ----------
          X : numpy.ndarray, with shape (n_samples, n_features)
              The data to fit.
          y : Ignored
              This is ignored.
  
          Returns
          -------
          self
          """
          # fit a regular regression model
          orig_fit(self, X, y=y)
  
          if self.constrain:
              # also record the training data min and max
              self.y_min = np.min(y)
              self.y_max = np.max(y)
  
          if self.rescale:
              # also record the means and SDs for the training set
              y_hat = orig_predict(self, X)
              self.yhat_mean = np.mean(y_hat)
              self.yhat_sd = np.std(y_hat)
              self.y_mean = np.mean(y)
              self.y_sd = np.std(y)
  
          return self
  
      @wraps(cls.predict)
      def predict(self, X: np.ndarray) -> np.ndarray:
          """
          Predict with regressor and rescale.
  
          Make predictions with the super class, and then adjust them using the
          stored min, max, means, and standard deviations.
  
          Parameters
          ----------
          self
              The instance itself
          X : numpy.ndarray, with shape (n_samples,)
              The data to predict.
  
          Returns
          -------
          numpy.ndarray
              The prediction results.
          """
          # get the unconstrained predictions
          res = orig_predict(self, X)
  
          if self.rescale:
              # convert the predictions to z-scores,
              # then rescale to match the training set distribution
              res = (
                  ((res - self.yhat_mean) / self.yhat_sd) * self.y_sd
              ) + self.y_mean
  
          if self.constrain:
              # apply min and max constraints
              res = np.array(
                  [
                      max(self.y_min, min(self.y_max, pred))
                      for pred in res
                  ]
              )
  
          return res
  
      @classmethod
      @wraps(cls._get_param_names)
      def _get_param_names(class_x):
          """
          Get kwargs for superclass and add new kwargs.
  
          This is adapted from scikit-learn's ``BaseEstimator`` class.
          It gets the kwargs for the superclass's init method and adds the
          kwargs for newly added ``__init__()`` method.
  
          Parameters
          ----------
          class_x
              The superclass from which to retrieve param names.
  
          Returns
          -------
          List[str]
              A list of parameter names for the class's init method.
  
          Raises
          ------
          RuntimeError
              If `varargs` exist in the scikit-learn estimator.
          """
          # initialize the empty list of parameter names
          args = []
  
          try:
              # get signature of the original init method
              init = getattr(
                  orig_init, "deprecated_original", orig_init
              )
              init_signature = inspect.signature(init)
  
              # get all parameters excluding 'self'
              original_parameters = [
                  p
                  for p in init_signature.parameters.values()
                  if p.name != "self" and p.kind != p.VAR_KEYWORD
              ]
  
              # there should be no varargs
              for parameter in original_parameters:
                  if parameter.kind == parameter.VAR_POSITIONAL:
                      raise RuntimeError(
                          "scikit-learn estimators should always specify their "
                          "parameters in the signature of their __init__ (no "
                          f"varargs). {cls} with constructor {init_signature} "
                          "doesn't follow this convention."
                      )
                  else:
                      args.append(parameter.name)
  
          except TypeError:
              pass
  
          # now get the additional rescaling arguments
          rescale_args = list(
              inspect.signature(class_x.__init__).parameters.keys()
          )
  
          # Remove 'self'
          rescale_args.remove("self")
  
          # add the rescaling arguments to the original arguments and sort
          args += rescale_args
          args.sort()
  
          return args
  
      @wraps(cls.__init__)
      def init(
          self, constrain: bool = True, rescale: bool = True, **kwargs
      ):  # noqa: D417
          """
          Initialize things in the right order.
  
          Parameters
          ----------
          constrain : bool, default=True
              Whether to constrain predictions within min and max values.
          rescale : bool, default=True
              Whether to rescale prediction values using z-scores.
          kwargs : Dict[str, Any]
              Keyword arguments for base class.
          """
          # pylint: disable=W0201
          self.constrain = constrain
          self.rescale = rescale
          self.y_min = None
          self.y_max = None
          self.yhat_mean = None
          self.yhat_sd = None
          self.y_mean = None
          self.y_sd = None
          orig_init(self, **kwargs)
  
      # Override original functions with new ones
      cls.__init__ = init
      cls.fit = fit
      cls.predict = predict
      cls._get_param_names = _get_param_names
      cls.rescale = True
  
      # Return modified class
      return cls
  
imports: from __future__ import annotations
  import inspect
  import logging
  import sys
  import time
  from collections import Counter, defaultdict
  from csv import DictWriter, excel_tab
  from functools import wraps
  from importlib import import_module
  from pathlib import Path
  from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Set, Tuple, Type, Union
  import joblib
  import numpy
  import scipy.sparse
  from sklearn.base import BaseEstimator, TransformerMixin
  from sklearn.feature_selection import SelectKBest
  from sklearn.metrics import accuracy_score, confusion_matrix, precision_recall_fscore_support
  from sklearn.model_selection import KFold, LeaveOneGroupOut, ShuffleSplit, StratifiedKFold
  from skll.data import FeatureSet
  from skll.metrics import _CUSTOM_METRICS, _PREDEFINED_CUSTOM_METRICS, use_score_func
  from skll.types import ComputeEvalMetricsResults, ConfusionMatrix, FeaturesetIterator, FoldMapping, IdType, IndexIterator, LabelType, PathOrStr, SparseFeatureMatrix
  from skll.utils.constants import CLASSIFICATION_ONLY_METRICS, CORRELATION_METRICS, REGRESSION_ONLY_METRICS, UNWEIGHTED_KAPPA_METRICS, WEIGHTED_KAPPA_METRICS
  from skll.version import VERSION
label_desc: Use image node_id 9 for calling a global function with example usage: rescaled(cls) and returns: cls, cls, self, res, args