class_docstr: TSShiftPerturber adds random lag in a time continuous block of the
  time series data. The lag introduction cause gap in the data, which is
  imputed using the specified interpolation function.
class_docstr_tok: ["TSShiftPerturber","adds","random","lag","in","a","time","continuous","block","of","the","time","series","data",".","The","lag","introduction","cause","gap","in","the","data",",","which","is","imputed","using","the","specified","interpolation","function","."]
code: def _transform(
      self,
      n_perturbations: int = 1,
      block_selector: BlockSelector = None,
  ):
      n_blocks = self._parameters.get("n_blocks")
      max_shift = self._parameters.get("max_shift")
      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]).astype("float32")
      length, dim = data.shape
  
      perturbed_data = []
      margin = length - max(max_shift, block_length)
  
      for i in range(n_perturbations):
          p_data = np.zeros_like(data)
          for j in range(dim):
              y_data = data[:, j]
              px_data = x_data.copy()
  
              if block_selector is None:
                  blocks = np.random.randint(
                      max_shift, margin, n_blocks
                  )
              else:
                  blocks = block_selector.select_start_point(
                      x=self._data, n=n_blocks, margin=margin
                  )
              for b in blocks:
                  shift = (2 * np.random.random() - 1) * max_shift
                  px_data[b : (b + block_length)] = (
                      x_data[b : (b + block_length)] + shift
                  )
  
              ix = np.argsort(px_data)
              poly = interp1d(
                  px_data[ix],
                  y_data[ix],
                  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_shift_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 TSShiftPerturber obj's underlying member method code with example usage: obj._transform(n_perturbations, block_selector) and returns: perturbed_data