Skip to content Skip to sidebar Skip to footer

How To Convert 2d Array Into Format That Keras+lstm Needs

I have a 5000 by 9 2d numpy array of features trainX which are the features of a time sequence. I also have a 1d numpy array of floating point feature labels trainY. This is exact

Solution 1:

The format is (samples, timeSteps, features)

How many sequences do you have? It sounds like one sequence of 5000 steps, is that right?

Then the format is (1,5000,9).

The labels should also be (1,5000,1), if you have one label per time step. (Then use return_sequences=True). Otherwise labels are (1,1).


Optionally, you may want to split your single sequence in many segments, in a classical sliding window case, for instance, where you'd have many samples with less time steps, such as (4998,3,1), supposing you want a 3-step window. Then the labels should follow: (4998,1).

Post a Comment for "How To Convert 2d Array Into Format That Keras+lstm Needs"