vendredi 3 septembre 2021

Time series data augmentation ( Rotation)

I am trying data augmentation techniques specifically "Random Transformations" on my time series data.

I have a data set with the shape (4708, 10), I am applying a technique "Rotation" on my dataset, for every other technique it works but for rotation it throws this error.

IndexError: tuple index out of range

here is the code I am trying

def rotation(x):
flip = np.random.choice([-1, 1], size=(x.shape[0],x.shape[1]))
rotate_axis = np.arange(x.shape[1])
np.random.shuffle(rotate_axis)    
return flip[:,np.newaxis,:] * x[:,:,rotate_axis]

When I try to call this method like this

data_rotation = np.apply_along_axis(rotation,1,data1)

it gives the following error

   ---------------------------------------------------------------------------
IndexError   Traceback (most recent call last)
<ipython-input-62-5cb011189740> in <module>
----> 1 data_after_rotation = np.apply_along_axis(rotation,1,data1)

<__array_function__ internals> in apply_along_axis(*args, **kwargs)

/opt/anaconda3/envs/tensorflow_env/lib/python3.6/site-packages/numpy/lib/shape_base.py in apply_along_axis(func1d, axis, arr, *args, **kwargs)
    377             'Cannot apply_along_axis when any iteration dimensions are 0'
    378         ) from None
--> 379     res = asanyarray(func1d(inarr_view[ind0], *args, **kwargs))
    380 
    381     # build a buffer for storing evaluations of func1d.

<ipython-input-55-31f976aecf3a> in rotation(x)
      1 def rotation(x):
----> 2     flip = np.random.choice([-1, 1], size=(x.shape[0],x.shape[1]))
      3     rotate_axis = np.arange(x.shape[1])
      4     np.random.shuffle(rotate_axis)
      5     return flip[:,np.newaxis,:] * x[:,:,rotate_axis]

IndexError: tuple index out of range

I dont understand how to apply this method when I have a dataset of shape (4708,10). I understand the error because the method was specifically for a dataset with 3 columns and my dataset has 10 columns. This could be the reason but i am not getting this, how to fix it.

Any help will be highly appreciated.




Aucun commentaire:

Enregistrer un commentaire