code: def rename_feature(
      spec,
      current_name,
      new_name,
      rename_inputs=True,
      rename_outputs=True,
  ):
      """
      Rename a feature in the specification.
  
      Parameters
      ----------
      spec: Model_pb
          The specification containing the feature to rename.
  
      current_name: str
          Current name of the feature. If this feature doesn't exist, the rename
          is a no-op.
  
      new_name: str
          New name of the feature.
  
      rename_inputs: bool
          Search for `current_name` only in the input features (i.e ignore output
          features)
  
      rename_outputs: bool
          Search for `current_name` only in the output features (i.e ignore input
          features)
  
      Examples
      --------
      .. sourcecode:: python
  
          # In-place rename of spec
          >>> coremltools.utils.rename_feature(spec, 'old_feature', 'new_feature_name')
      """
      from coremltools.models import MLModel
  
      if not rename_inputs and not rename_outputs:
          return
  
      changed_input = False
      changed_output = False
  
      if rename_inputs:
          for input in spec.description.input:
              if input.name == current_name:
                  input.name = new_name
                  changed_input = True
  
      if rename_outputs:
          for output in spec.description.output:
              if output.name == current_name:
                  output.name = new_name
                  changed_output = True
  
          if spec.description.predictedFeatureName == current_name:
              spec.description.predictedFeatureName = new_name
  
          if (
              spec.description.predictedProbabilitiesName
              == current_name
          ):
              spec.description.predictedProbabilitiesName = new_name
  
      if not changed_input and not changed_output:
          return
  
      # Rename internally in NN model
      nn = None
      for nn_type in [
          "neuralNetwork",
          "neuralNetworkClassifier",
          "neuralNetworkRegressor",
      ]:
          if spec.HasField(nn_type):
              nn = getattr(spec, nn_type)
  
      if nn is not None:
          for layer in nn.layers:
              if rename_inputs:
                  for index, name in enumerate(layer.input):
                      if name == current_name:
                          layer.input[index] = new_name
                  if rename_outputs:
                      for index, name in enumerate(layer.output):
                          if name == current_name:
                              layer.output[index] = new_name
  
          if spec.HasField("neuralNetworkClassifier"):
              if nn.labelProbabilityLayerName == current_name:
                  nn.labelProbabilityLayerName = new_name
  
      # Rename internally for feature vectorizer
      if spec.HasField("featureVectorizer") and rename_inputs:
          for input in spec.featureVectorizer.inputList:
              if input.inputColumn == current_name:
                  input.inputColumn = new_name
                  changed_input = True
  
      # Rename for pipeline models
      pipeline = None
      if spec.HasField("pipeline"):
          pipeline = spec.pipeline
      elif spec.HasField("pipelineClassifier"):
          pipeline = spec.pipelineClassifier.pipeline
      elif spec.HasField("pipelineRegressor"):
          pipeline = spec.pipelineRegressor.pipeline
  
      if pipeline is not None:
          for index, model in enumerate(pipeline.models):
              rename_feature(
                  model,
                  current_name,
                  new_name,
                  rename_inputs or (index != 0),
                  rename_outputs or (index < len(spec.pipeline.models)),
              )
  
imports: import math
  import numpy
  import os
  import six
  import warnings
  import sys
  from coremltools.proto import Model_pb2
  from coremltools.models._deprecation import deprecated
  from .._deps import _HAS_SKLEARN
label_desc: Use image node_id 16 for calling a global function with example usage: rename_feature(spec, current_name, new_name, rename_inputs, rename_outputs) without return types