I have a timestep of 10. I did following:
i transformed (200, 5)
into (20, 10, 5)
for X and i transformed (200,1)
into (20, 10, 1)
for Y
But i do not understand Y. Do i pass it as (20, 10, 1)
or as (20, 1)
?
x = np.array(data_x)
x = data_x.reshape((int(data_x.shape[0]/10), 10, data_x.shape[1]))
y = np.array(data_y)
y = y.reshape((int(data_x.shape[0]/10),10, 1))
If you are planning to build a time-series model or a sequence based model, it would be beneficial to use either tf.keras.preprocessing.sequence.TimeseriesGenerator or sklearn.model_selection.time_series_split to generate the samples. These are well documented.
But i do not understand Y. Do i pass it as (20, 10, 1) or as (20, 1)?
Well this is difficult to answer because you have not provided your use-case or objective. Assuming you are building a time-series or sequence based model with a timestep of 10 on an input dataframe with 200 samples and 5 features, we need the X with shape (190, 10, 5) and y with shape (190, 1).
Using TimeseriesGenerator
import tensorflow as tf
import numpy as np
from tensorflow.keras.preprocessing.sequence import TimeseriesGenerator as tsg
tf.__version__ # '2.4.1'
TIMESTEPS = 10
# data_x = np.random.random((200,5))
data_x = np.arange((200))
data_y = np.arange((200))
data = tsg(
data=data_x, # shape (200,5)
targets=data_y, # shape (200,1) or just 200
length=TIMESTEPS,
sampling_rate=1,
stride=1,
start_index=0,
end_index=None,
shuffle=False,
reverse=False,
batch_size=4)
[(x, y) for x,y in zip(data[0][0], data[0][1])]
You can also use sklearn's model_selection.TimeSeriesSplit for creating rolling or expanding sets of time series X,y pairs..
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.