class_docstr: Base class providing API and common functions for all multi-label
  classifiers.
  
  Implements base functionality for ML classifiers, especially the get/set params for
  scikit-learn compatibility.
  
  Attributes
  ----------
  copyable_attrs : List[str]
      list of attribute names that should be copied when class is cloned
docstr: Ensure the desired output format
  
  This function ensures that output format follows the
  density/sparsity requirements of base classifier.
  
  Parameters
  ----------
  
  matrix : array-like matrix
      An input feature matrix of shape :code:`(n_samples)` or
      :code:`(n_samples, n_outputs)` or a sparse matrix of shape
      :code:`(n_samples, n_outputs)`
  
  sparse_format: str (default is csr)
      Requested format of returned :code:`scipy.sparse` matrix,
      if sparse is returned
  
  enforce_sparse : bool (default is False)
      Ignore :code:`require_dense` and enforce sparsity, useful
      internally
  
  Returns
  -------
  array-like or sparse matrix
      Transformed X values of shape :code:`(n_samples, n_features)`
  
  .. note:: If :code:`require_dense` was set to :code:`True` for
      input features in the constructor, the returned value is an
      array-like of array-likes. If :code:`require_dense` is
      set to :code:`false`, a sparse matrix of format
      :code:`sparse_format` is returned, if possible - without cloning.
docstr_tok: ["Ensure","the","desired","output","format","This","function","ensures","that","output","format","follows","the","density\/sparsity","requirements","of","base","classifier",".","Parameters","--","--","--","--","--","matrix",":","array-like","matrix","An","input","feature","matrix","of","shape",":","code",":","`","(","n_samples",")","`","or",":","code",":","`","(","n_samples",",","n_outputs",")","`","or","a","sparse","matrix","of","shape",":","code",":","`","(","n_samples",",","n_outputs",")","`","sparse_format",":","str","(","default","is","csr",")","Requested","format","of","returned",":","code",":","`","scipy.sparse","`","matrix",",","if","sparse","is","returned","enforce_sparse",":","bool","(","default","is","False",")","Ignore",":","code",":","`","require_dense","`","and","enforce","sparsity",",","useful","internally","Returns","--","--","--","-","array-like","or","sparse","matrix","Transformed","X","values","of","shape",":","code",":","`","(","n_samples",",","n_features",")","`","..","note",":",":","If",":","code",":","`","require_dense","`","was","set","to",":","code",":","`","True","`","for","input","features","in","the","constructor",",","the","returned","value","is","an","array-like","of","array-likes",".","If",":","code",":","`","require_dense","`","is","set","to",":","code",":","`","false","`",",","a","sparse","matrix","of","format",":","code",":","`","sparse_format","`","is","returned",",","if","possible","-","without","cloning","."]
code: def _ensure_output_format(
      self, matrix, sparse_format="csr", enforce_sparse=False
  ):
      """Ensure the desired output format
  
      This function ensures that output format follows the
      density/sparsity requirements of base classifier.
  
      Parameters
      ----------
  
      matrix : array-like matrix
          An input feature matrix of shape :code:`(n_samples)` or
          :code:`(n_samples, n_outputs)` or a sparse matrix of shape
          :code:`(n_samples, n_outputs)`
  
      sparse_format: str (default is csr)
          Requested format of returned :code:`scipy.sparse` matrix,
          if sparse is returned
  
      enforce_sparse : bool (default is False)
          Ignore :code:`require_dense` and enforce sparsity, useful
          internally
  
      Returns
      -------
      array-like or sparse matrix
          Transformed X values of shape :code:`(n_samples, n_features)`
  
      .. note:: If :code:`require_dense` was set to :code:`True` for
          input features in the constructor, the returned value is an
          array-like of array-likes. If :code:`require_dense` is
          set to :code:`false`, a sparse matrix of format
          :code:`sparse_format` is returned, if possible - without cloning.
      """
      is_sparse = issparse(matrix)
  
      if is_sparse:
          if self.require_dense[1] and not enforce_sparse:
              if matrix.shape[1] != 1:
                  return matrix.toarray()
              elif matrix.shape[1] == 1:
                  return np.ravel(matrix.toarray())
          else:
              if sparse_format is None:
                  return matrix
              else:
                  return get_matrix_in_format(matrix, sparse_format)
      else:
          if self.require_dense[1] and not enforce_sparse:
              # ensuring 1d
              if len(matrix.shape) > 1:
                  # a regular dense np.matrix or np.array of np.arrays
                  return np.ravel(matrix)
              else:
                  return matrix
          else:
              # ensuring 2d
              if len(matrix.shape) == 1:
                  matrix = matrix.reshape((matrix.shape[0], 1))
              return matrix_creation_function_for_format(sparse_format)(
                  matrix
              )
  
file_path: scikit-multilearn/skmultilearn/base/base.py
imports: import numpy
  from ..utils import get_matrix_in_format, matrix_creation_function_for_format
  from scipy.sparse import issparse
  from sklearn.base import BaseEstimator, ClassifierMixin
label_desc: Use image node_id 4 for calling the MLClassifierBase obj's underlying member method code with example usage: obj._ensure_output_format(matrix, sparse_format, enforce_sparse) and returns: matrix_creation_function_for_format, matrix, matrix, get_matrix_in_format, np, matrix, np