code: def apply(self, targets, train=True):
      if targets is None and train:
          raise ValueError("targets is None")
      elif targets is None and not train:
          return
  
      # validate labels against data
      targets = np.array(targets) if type(targets) == list else targets
      if len(targets.shape) > 1 and targets.shape[1] == 1:
          targets = np.squeeze(targets, axis=1)
  
      # handle numeric targets (regression)
      if len(targets.shape) == 1 and not isinstance(targets[0], str):
          # numeric targets
          if not self.get_classes() and train:
              warnings.warn(
                  "Task is being treated as REGRESSION because "
                  + "either class_names argument was not supplied or is_regression=True. "
                  + "If this is incorrect, change accordingly."
              )
          if not self.get_classes():
              targets = np.array(targets, dtype=np.float32)
      # string targets (classification)
      elif len(targets.shape) == 1 and isinstance(targets[0], str):
          if not train and self.le is None:
              raise ValueError(
                  "LabelEncoder has not been trained. Call with train=True"
              )
          if train:
              self.le = LabelEncoder()
              self.le.fit(targets)
              if self.get_classes():
                  warnings.warn(
                      "class_names argument was ignored, as they were extracted from string labels in dataset"
                  )
              self.set_classes(self.le.classes_)
          targets = self.le.transform(
              targets
          )  # convert to numerical targets for classfication
      # handle categorical targets (classification)
      elif len(targets.shape) > 1:
          if not self.get_classes():
              raise ValueError(
                  "targets are 1-hot or multi-hot encoded but class_names is empty. "
                  + "The classes argument should have been supplied."
              )
          else:
              if train and len(self.get_classes()) != targets.shape[1]:
                  raise ValueError(
                      "training targets suggest %s classes, but class_names are %s"
                      % (targets.shape[1], self.get_classes())
                  )
  
      # numeric targets (classification)
      if len(targets.shape) == 1 and self.get_classes():
          if np.issubdtype(type(max(targets)), np.floating):
              warnings.warn(
                  "class_names implies classification but targets array contains float(s) instead of integers or strings"
              )
  
          if train and (len(set(targets)) != int(max(targets) + 1)):
              raise ValueError(
                  "len(set(targets) is %s but max(targets)+1 is  %s"
                  % (len(set(targets)), int(max(targets) + 1))
              )
          targets = keras.utils.to_categorical(
              targets, num_classes=len(self.get_classes())
          )
      if train:
          self.train_called = True
      return targets
  
imports: from .imports import *
  from subprocess import Popen
label_desc: Use image node_id 4 for calling the YTransform obj's underlying member method code with example usage: obj.apply(targets, train) and returns: targets