class_docstr: TSImputePerturber removes random block from the time series data, and imputes
  the value with specified interpolation method.
class_docstr_tok: ["TSImputePerturber","removes","random","block","from","the","time","series","data",",","and","imputes","the","value","with","specified","interpolation","method","."]
code: def _transform(
      self,
      n_perturbations: int = 1,
      block_selector: BlockSelector = None,
  ):
      padding = self._parameters.get("padding")
      n_blocks = self._parameters.get("n_blocks")
      sparsity = self._parameters.get("sparsity")
      block_length = self._parameters.get("block_length")
      interpolation_kind = self._parameters.get("interpolation_kind")
  
      data = to_np_array(self._data)
      x_data = np.arange(data.shape[0])
      length, dim = data.shape
  
      perturbed_data = []
  
      for i in range(n_perturbations):
          p_data = np.zeros_like(data)
          for j in range(dim):
              y_data = data[:, j]
              margin = length - block_length - padding
              if block_selector is None:
                  blocks = np.random.randint(padding, margin, n_blocks)
              else:
                  blocks = block_selector.select_start_point(
                      x=self._data, n=n_blocks, margin=margin
                  )
              block = []
              for b in blocks:
                  block = block + list(range(b, b + block_length))
              block = np.unique(block)
              index = list(set(x_data).difference(block))
              n = int((len(index) - 2 * padding) * sparsity)
              index = (
                  index[:padding]
                  + sorted(
                      np.random.choice(
                          index[padding:-padding], n, replace=False
                      )
                  )
                  + index[-padding:]
              )
              poly = interp1d(
                  x_data[index],
                  y_data[index],
                  kind=interpolation_kind,
                  copy=True,
              )
              p_data[:, j] = poly(x_data)
          if isinstance(self._data, pd.DataFrame):
              p_data = pd.DataFrame(
                  p_data,
                  index=self._data.index,
                  columns=self._data.columns,
              )
          perturbed_data.append(p_data)
      return perturbed_data
  
file_path: AIX360/aix360/algorithms/tsutils/tsperturbers/ts_impute_perturber.py
imports: import numpy
  import pandas
  from typing import Union
  from scipy.interpolate import interp1d
  from aix360.algorithms.tsutils.tsframe import tsFrame, to_np_array
  from aix360.algorithms.tsutils.tsperturbers.tsperturber import BlockSelector, TSPerturber
label_desc: Use image node_id 5 for calling the TSImputePerturber obj's underlying member method code with example usage: obj._transform(n_perturbations, block_selector) and returns: perturbed_data