code: def _sparse_fit(self, X, strategy, missing_values, fill_value):
          
          mask_data = _get_mask(X.data, missing_values)
          n_implicit_zeros = X.shape[0] - np.diff(X.indptr)
  
          statistics = np.empty(X.shape[1])
  
          if strategy == "constant":
              # for constant strategy, self.statistcs_ is used to store
              # fill_value in each column
              statistics.fill(fill_value)
  
          else:
              for i in range(X.shape[1]):
                  column = X.data[X.indptr[i]:X.indptr[i + 1]]
                  mask_column = mask_data[X.indptr[i]:X.indptr[i + 1]]
                  column = column[~mask_column]
  
                  # combine explicit and implicit zeros
                  mask_zeros = _get_mask(column, 0)
                  column = column[~mask_zeros]
                  n_explicit_zeros = mask_zeros.sum()
                  n_zeros = n_implicit_zeros[i] + n_explicit_zeros
  
                  if strategy == "mean":
                      s = column.size + n_zeros
                      statistics[i] = np.nan if s == 0 else column.sum() / s
  
                  elif strategy == "median":
                      statistics[i] = _get_median(column,
                                                  n_zeros)
  
                  elif strategy == "most_frequent":
                      statistics[i] = _most_frequent(column,
                                                     0,
                                                     n_zeros)
          return statistics
docs: Fit the transformer on sparse data.