Preparing input data for classification using LSTM
15 views (last 30 days)
Show older comments
Ernest Modise - Kgamane
on 31 May 2024
Commented: Cris LaPierre
on 18 Aug 2024
I am interested in classifying graphs (senquence) data to category labels. I saw that I could use LSTM however, I would like know how the primary sequence data is store for inputing into the LSTM, I also want to know how to attach know labels to each graph for purpose of training.
In this there is a variable / struture called waveform, how was it constructed?
Please assist
2 Comments
Cris LaPierre
on 31 May 2024
The format is described at the top of the linked example.
You can also find it described at the top of this example: Sequence-to-One Regression Using Deep Learning
Accepted Answer
Cris LaPierre
on 31 May 2024
It is a mat file. This is a way of saving variables in MATLAB to a file (see save). It loads 3 variables to the Workspace
- data - a 1000x1 cell array. Each cell contains an nx3 array of signal data
- freq - 1000x1 array. This is the frequency of the corresponding observation
- labels - a 1000x1 categorical array containg the waveform label for the corresponding observation
You don't need to create a mat file. You just need to organze your data into a numObservations-by-1 cell array of sequences as the input data.
Each sequence (cell of data) is a numTimeSteps-by-numChannels numeric array, where numTimeSteps is the number of time steps of the sequence and numChannels is the number of channels of the sequence.
The label data is a numObservations-by-1 categorical vector.
You do not need to use freq for the example you are using.
5 Comments
Fan
on 14 Aug 2024
Hi Cris,
Sorry for jumpping into this answered question, but i do have a similar question thats been bugging me for a while. I think the Waveform example uses a timestep of 1 so that each row in a observation ( or in a cell), is 1 timepoint.
However, if I want to use a timestep of 5 sliding from time0 - timeN using a slideing window of 1, so basically creating another dimenssion within each observation, how should I organize my input data and label vector? Do i simply make each cell a 3d array, like timestep by channel by number of sliding window?
Also, does it matter if I transpose the input from time by channel to channel by time?
Cris LaPierre
on 18 Aug 2024
There is no time data in the linked eample. Instead, index is used (1:numel)..You might be able to back out the actual time step size using the freq data if necessary, but it will require some exta work, as the number of periods captured varies across observations.
If you are following the LSTM example, then yes, order matters. You can read more about the input syntax for trainnet here:
As for your question about data format, that can be specified in the InputDataFormats training option. From the linked doc page:
- "The size and shape of the numeric arrays or dlarray objects that represent sequences depend on the type of sequence data and must be consistent with the InputDataFormats training option."
More Answers (0)
See Also
Categories
Find more on Image Data Workflows in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!