code: def process_or_validate_classifier_output_features(
      output_features, class_labels, supports_class_scores=True
  ):
      """
      Given a list of class labels and a list of output_features, validate the
      list and return a valid version of output_features with all the correct
      data type information included.
      """
  
      def raise_error(msg):
          raise ValueError("Classifier error: %s" % msg)
  
      class_labels = list(class_labels)
  
      # First, we need to determine the type of the classes.
      _int_types = (int, bool, _np.bool_, _np.int32, _np.int64)
  
      if all(isinstance(cl, _int_types) for cl in class_labels):
          output_class_type = datatypes.Int64()
  
      elif all(isinstance(cl, str) for cl in class_labels):
          output_class_type = datatypes.String()
  
      else:
          raise ValueError(
              "Class labels must be all of type int or all of type string."
          )
  
      if output_features is None:
          out = [("classLabel", output_class_type)]
  
          if supports_class_scores:
              out += [
                  (
                      "classProbability",
                      datatypes.Dictionary(output_class_type),
                  )
              ]
  
      elif isinstance(output_features, str):
          out = [(output_features, output_class_type)]
  
          if supports_class_scores:
              out += [
                  (
                      "classProbability",
                      datatypes.Dictionary(output_class_type),
                  )
              ]
  
      elif (
          isinstance(output_features, (list, tuple))
          and all(isinstance(fn, str) for fn in output_features)
          and len(output_features) == 2
      ):
          if supports_class_scores:
              out = [
                  (output_features[0], output_class_type),
                  (
                      output_features[1],
                      datatypes.Dictionary(output_class_type),
                  ),
              ]
          else:
              raise ValueError(
                  "Classifier model (as trained) does not support output scores for classes."
              )
  
      elif is_valid_feature_list(output_features):
          output_features = [
              (k, datatypes._normalize_datatype(dt))
              for k, dt in output_features
          ]
  
          if len(output_features) == 1 or not supports_class_scores:
              if not output_features[0][1] == output_class_type:
                  raise ValueError(
                      "Type of output class feature does not match type of class labels."
                  )
  
          else:
              # Make sure the first two output features specified give the output
              # class field and the output class scores dictionary field
              if isinstance(
                  output_features[0][1], datatypes.Dictionary
              ) and isinstance(
                  output_features[1][1], output_class_type
              ):
                  output_features[0], output_features[1] = (
                      output_features[1],
                      output_features[0],
                  )
  
              if not isinstance(
                  output_features[1][1], datatypes.Dictionary
              ):
                  raise_error(
                      "Output features class scores should be dictionary type."
                  )
  
              if output_features[1][1].key_type != output_class_type:
                  raise_error(
                      "Class scores dictionary key type does not match type of class labels."
                  )
  
              if output_features[0][1] != output_class_type:
                  raise_error(
                      "Specified type of output class does not match type of class labels."
                  )
  
          # NOTE: We are intentionally allowing the case where additional fields are allowed
          # beyond the original two features.
  
          out = output_features
  
      else:
          raise_error("Form of output features not recognized")
  
      return out
  
file_path: coremltools/coremltools/models/_feature_management.py
imports: import operator
  from collections import defaultdict
  from copy import copy
  from functools import reduce
  import numpy
  from .None import datatypes
label_desc: Use image node_id 1 for calling a global function with example usage: process_or_validate_classifier_output_features(output_features, class_labels, supports_class_scores) and returns: out