简体   繁体   中英

How to generate training samples for LSTM?

I have 100 invidual time series (units - index) within the dataframe below and want to train LSTM to predict the target ('RUL').

My data look like:

train.head()

cycles  os1 os2 sm2 sm3 sm4 sm6 sm7 sm8 sm9 sm11    sm12    sm13    sm14    sm15    sm17    sm20    sm21    RUL
unit                                                                            
1   1   -0.0007 -0.0004 641.82  1589.70 1400.60 21.61   554.36  2388.06 9046.19 47.47   521.66  2388.02 8138.62 8.4195  392 39.06   23.4190 191
1   2   0.0019  -0.0003 642.15  1591.82 1403.14 21.61   553.75  2388.04 9044.07 47.49   522.28  2388.07 8131.49 8.4318  392 39.00   23.4236 190
1   3   -0.0043 0.0003  642.35  1587.99 1404.20 21.61   554.26  2388.08 9052.94 47.27   522.42  2388.03 8133.23 8.4178  390 38.95   23.3442 189
1   4   0.0007  0.0000  642.35  1582.79 1401.87 21.61   554.45  2388.11 9049.48 47.13   522.86  2388.08 8133.83 8.3682  392 38.88   23.3739 188
1   5   -0.0019 -0.0002 642.37  1582.85 1406.22 21.61   554.00  2388.06 9055.15 47.28   522.19  2388.04 8133.80 8.4294  393 38.90   23.4044 187

The dimensionality is:

# Training data
X.shape
(20631, 18)


# Labels/targets
y.shape
(20631,)

So far, I've tried:

from keras.preprocessing.sequence import TimeseriesGenerator

data_gen = TimeseriesGenerator(X, y,
                               length=10, sampling_rate=2,
                               batch_size=2)

# Model
from keras.models import Sequential
from keras.layers import Dense, LSTM

model = Sequential()
model.add(LSTM(units=128, activation='relu', dropout=0.25, input_shape=(18,1))) # Input layer
model.add(Dense(units=1)) # Output layer
model.compile(optimizer='adam', loss='rmae')
#model.fit(x, y, epochs=30, batch_size=7)
model.fit_generator(data_gen, steps_per_epoch=len(data_gen), epochs=100)

...which yields:

ValueError: cannot copy sequence with size 5 to array axis with dimension 18

Help would be appreciated.

The model waits for and input (x) array/sequence with length of 18 ( input_shape=(18,1) ). But it gets one with length of 5. You shoud change the parameters of TimeseriesGenerator to length=18 and sampeling_rate=1 maybe, to generate imputs with length of 18.

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