class_docstr: Imputation transformer for completing missing values.
  
  Read more in the :ref:`User Guide <imputation>`.
  
  Parameters
  ----------
  missing_values : integer or "NaN", optional (default="NaN")
      The placeholder for the missing values. All occurrences of
      `missing_values` will be imputed. For missing values encoded as np.nan,
      use the string value "NaN".
  
  strategy : string, optional (default="mean")
      The imputation strategy.
  
      - If "mean", then replace missing values using the mean along
        the axis.
      - If "median", then replace missing values using the median along
        the axis.
      - If "most_frequent", then replace missing using the most frequent
        value along the axis.
  
  axis : integer, optional (default=0)
      The axis along which to impute.
  
      - If `axis=0`, then impute along columns.
      - If `axis=1`, then impute along rows.
  
  verbose : integer, optional (default=0)
      Controls the verbosity of the imputer.
  
  copy : boolean, optional (default=True)
      If True, a copy of X will be created. If False, imputation will
      be done in-place whenever possible. Note that, in the following cases,
      a new copy will always be made, even if `copy=False`:
  
      - If X is not an array of floating values;
      - If X is sparse and `missing_values=0`;
      - If `axis=0` and X is encoded as a CSR matrix;
      - If `axis=1` and X is encoded as a CSC matrix.
  
  Attributes
  ----------
  statistics_ : array of shape (n_features,)
      The imputation fill value for each feature if axis == 0.
  
  Notes
  -----
  - When ``axis=0``, columns which only contained missing values at `fit`
    are discarded upon `transform`.
  - When ``axis=1``, an exception is raised if there are rows for which it is
    not possible to fill in the missing values (e.g., because they only
    contain missing values).
docstr: Fit the transformer on sparse data.
docstr_tok: ["Fit","the","transformer","on","sparse","data","."]
code: def _sparse_fit(self, X, strategy, missing_values, axis):
      """Fit the transformer on sparse data."""
      # Imputation is done "by column", so if we want to do it
      # by row we only need to convert the matrix to csr format.
      if axis == 1:
          X = X.tocsr()
      else:
          X = X.tocsc()
  
      # Count the zeros
      if missing_values == 0:
          n_zeros_axis = np.zeros(X.shape[not axis], dtype=int)
      else:
          n_zeros_axis = X.shape[axis] - np.diff(X.indptr)
  
      # Mean
      if strategy == "mean":
          if missing_values != 0:
              n_non_missing = n_zeros_axis
  
              # Mask the missing elements
              mask_missing_values = _get_mask(X.data, missing_values)
              mask_valids = np.logical_not(mask_missing_values)
  
              # Sum only the valid elements
              new_data = X.data.copy()
              new_data[mask_missing_values] = 0
              X = sparse.csc_matrix(
                  (new_data, X.indices, X.indptr), copy=False
              )
              sums = X.sum(axis=0)
  
              # Count the elements != 0
              mask_non_zeros = sparse.csc_matrix(
                  (mask_valids.astype(np.float64), X.indices, X.indptr),
                  copy=False,
              )
              s = mask_non_zeros.sum(axis=0)
              n_non_missing = np.add(n_non_missing, s)
  
          else:
              sums = X.sum(axis=axis)
              n_non_missing = np.diff(X.indptr)
  
          # Ignore the error, columns with a np.nan statistics_
          # are not an error at this point. These columns will
          # be removed in transform
          with np.errstate(all="ignore"):
              return np.ravel(sums) / np.ravel(n_non_missing)
  
      # Median + Most frequent
      else:
          # Remove the missing values, for each column
          columns_all = np.hsplit(X.data, X.indptr[1:-1])
          mask_missing_values = _get_mask(X.data, missing_values)
          mask_valids = np.hsplit(
              np.logical_not(mask_missing_values), X.indptr[1:-1]
          )
  
          # astype necessary for bug in numpy.hsplit before v1.9
          columns = [
              col[astype(mask, bool, copy=False)]
              for col, mask in zip(columns_all, mask_valids)
          ]
  
          # Median
          if strategy == "median":
              median = np.empty(len(columns))
              for i, column in enumerate(columns):
                  median[i] = _get_median(column, n_zeros_axis[i])
  
              return median
  
          # Most frequent
          elif strategy == "most_frequent":
              most_frequent = np.empty(len(columns))
  
              for i, column in enumerate(columns):
                  most_frequent[i] = _most_frequent(
                      column, 0, n_zeros_axis[i]
                  )
  
              return most_frequent
  
imports: import warnings
  import numpy
  import numpy.ma
  from scipy import sparse
  from scipy import stats
  from ..base import BaseEstimator, TransformerMixin
  from ..utils import check_array
  from ..utils.fixes import astype
  from ..utils.sparsefuncs import _get_median
  from ..utils.validation import check_is_fitted
  from ..utils.validation import FLOAT_DTYPES
  from ..externals import six
label_desc: Use image node_id 3 for calling the Imputer obj's underlying member method code with example usage: obj._sparse_fit(X, strategy, missing_values, axis) and returns: unknown, median, most_frequent