code: def _check_instances(instances, namespace=None):
      """Helper to ensure all instances are named.
  
      Check if ``instances`` is formatted as expected, and if not convert
      formatting or throw traceback error if impossible to anticipate formatting.
  
      Parameters
      ----------
      instances : iterable
          instance iterable to test.
  
      namespace: list, optional
          list of assigned instance names.
  
      Returns
      -------
      formatted : list or dict
          formatted ``instances`` object. Will be formatted as a dict if
          preprocessing cases are detected, otherwise as a list. The dict will
          contain lists identical to those in the single preprocessing case.
          Each list is of the form ``[('name', instance)]`` and no names overlap.
  
      Raises
      ------
      LayerSpecificationError :
          Raises error if formatting fails, which is most likely due to wrong
          ordering of tuple entries, or wrong argument in the wrong position.
  
      See Also
      --------
          :class:`mlens.ensemble.base.Layer`
      """
      if not namespace:
          namespace = list()
  
      is_iterable = isinstance(instances, (list, tuple, dict))
      if not is_iterable:
          instances = [instances]
      if not instances or None in instances:
          return None
  
      if _assert_format(instances, namespace):
          out = instances
      else:
          out = _format_instances(instances, namespace=namespace)
      return out
  
file_path: mlens/mlens/utils/formatting.py
imports: from __future__ import division, print_function
  from collections import Counter
  from .checks import assert_valid_estimator, assert_correct_format
  from .exceptions import LayerSpecificationError
  from ..externals.sklearn.base import clone
label_desc: Use image node_id 7 for calling a global function with example usage: _check_instances(instances, namespace) and returns: out, None