简体   繁体   中英

How can I resize on time-series data on python

I'm trying to do deep-learning on time-series data.

There are 12 features for each data, but every series data don't have the same amount of data.

Some shape is [48,12], and some is [54,12], I'm trying to resize them into [50,12].

All I know until now is using resize in skimage.transform , but I don't know if it works well or not.

Is there any other solution for doing this?

For example, one of the features in the data looks like below. The shape is [55, 1] I would like to reshape it to [50, 1].

a = np.array[-5.529309, -4.6293,   -3.068647, -4.897388, -4.39951,  -4.753769, -3.729291,
 -4.973984, -5.060155, -4.686748, -4.696322, -3.939932, -3.470778, -6.209103,
 -5.586756, -4.466532, -3.193116, -5.337818, -5.596331, -4.006954, -3.499502,
 -3.413331, -6.304848, -4.322914, -4.246317, -5.759098, -5.893142, -6.381444,
 -4.52398,  -4.198445, -5.634629, -6.276124, -5.17505,  -4.322914, -4.198445,
 -4.600576, -4.39951,  -4.945261, -5.759098, -4.677173, -3.623971, -5.692076,
 -6.563361, -5.462287, -4.868664, -5.941015, -6.400594, -5.692076, -4.591002,
 -6.027186, -5.960164, -6.256975, -5.414414, -5.730374, -6.726129]

If I using resize, the data will look like below.

Before resize and after resize:

1

One choice will be using TimeSeriesResampler in tslearn. This resizes a given time series to a fixed size you specified, by resampling data by (linear) interpolation. https://tslearn.readthedocs.io/en/stable/gen_modules/preprocessing/tslearn.preprocessing.TimeSeriesResampler.html

Example:

from tslearn.preprocessing import TimeSeriesResampler
ts = np.arange(5)
new_ts = TimeSeriesResampler(sz=9).fit_transform(ts)
final_ts = np.squeeze(new_ts)
print(ts)   # [0 1 2 3 4]
print(new_ts)  # [[[0. ] [0.5] [1. ] [1.5] [2. ] [2.5] [3. ] [3.5] [4. ]]]
print(final_ts)  # [0. 0.5 1. 1.5 2. 2.5 3. 3.5 4.]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM