code: def _format_instances(instances):
      """Format a list of instances to a list of named estimator tuples."""
      named_instances = []
      for val in instances:
          # Check that the instance appears correctly specified
          if not isinstance(val, (list, tuple, set)):
              # val is the instance
              instance = val
          else:
              # val is a list-like object. Assume instance is the last entry
              instance = val[-1]
  
          # Check if it appears to be an estimator
          assert_valid_estimator(instance)
  
          try:
              # Format instance names
  
              # We keep the instance as a list to change possible duplicate names
              # exploiting that lists are mutable, before switching to tuple
              if instance == val:
                  tup = [instance.__class__.__name__.lower(), instance]
              else:
                  tup = ["-".join(val[0].split()).lower(), val[-1]]
  
              named_instances.append(tup)
  
          except Exception as e:
              msg = (
                  "Could not format instance %s. Check that passed instance "
                  "iterables follow correct syntax:\n"
                  "- if multiple preprocessing cases, pass a dictionary with "
                  "instance lists as values and case name as key.\n"
                  "- else, pass list of (named) instances.\n"
                  "See documentation for further information.\n"
                  "Error details: %r"
              )
              raise ValueError(msg % (instance, e))
  
      # Check and correct duplicate names
      duplicates = Counter([tup[0] for tup in named_instances])
      duplicates = {
          key: val for key, val in duplicates.items() if val > 1
      }
  
      out = []  # final named_instances list
  
      name_count = {key: 1 for key in duplicates}
      for name, instance in named_instances:
          if name in duplicates:
              current_name_count = name_count[name]  # fix before update
              name_count[name] += 1
              name += "-%d" % current_name_count  # rename
          out.append((name, instance))
      return sorted(out)
  
file_path: mlens/mlens/model_selection/_base_functions.py
imports: from __future__ import division
  from collections import Counter
  from ..parallel import EvalLearner, EvalTransformer, Pipeline
  from ..utils.formatting import _assert_format
  from ..utils.checks import assert_valid_estimator
  from ..externals.sklearn.base import clone
label_desc: Use image node_id 5 for calling a global function with example usage: _format_instances(instances) and returns: sorted