Preparing input data for classification using LSTM
8 ビュー (過去 30 日間)
古いコメントを表示
Ernest Modise - Kgamane
2024 年 5 月 31 日
編集済み: Cris LaPierre
2024 年 6 月 14 日
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 件のコメント
Cris LaPierre
2024 年 5 月 31 日
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
採用された回答
Cris LaPierre
2024 年 5 月 31 日
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.
3 件のコメント
Cris LaPierre
2024 年 6 月 12 日
編集済み: Cris LaPierre
2024 年 6 月 14 日
Thank you for adding your data. That makes it easier to help.
If you separate your data into a cell array where each cell contains 3 signals of the same type (a 100x3 matrix), you can the use the example code. The challenging part is that you do not have an exact multiple of 3 of all your signals. That makes the actual code a little more complicated. Still, something like this should work.
Datain = readmatrix('LSTMdataIn.xlsx');
% orient the data to be time x sample
Datain = Datain';
% split the data into an numObservatoins x 1 cell array
% Each cell contains a 100x3 matrix. All 3 signals are of the same type
% Also create
data = {};
labels = {};
s=2;
idx = [0 200 399 598 798 997];
sig = 1:3:997;
L = {'graphtype1' 'graphtype2' 'graphtype3' 'graphtype4' 'graphtype5'};
for c = 2:length(sig)
if sig(c)>idx(s-1) && sig(c)+2<=idx(s)
data(end+1,:) = {Datain(:,sig(c-1):sig(c)-1)};
labels(end+1,:) = L(s-1);
elseif sig(c)==idx(s)
data(end+1,:) = {Datain(:,sig(c-1):sig(c)-1)};
labels(end+1,:) = L(s-1);
s=s+1;
else
s=s+1;
% skip cells that would contain a mix of signal types
continue
end
end
You can then pick up using the code from the example
numChannels = size(data{1},2);
idx = [3 4 5 12];
figure
tiledlayout(2,2)
for i = 1:4
nexttile
stackedplot(data{idx(i)},DisplayLabels="Channel "+string(1:numChannels))
xlabel("Time Step")
title("Class: " + string(labels(idx(i))))
end
labels = categorical(labels);
classNames = categories(labels)
numObservations = numel(data);
[idxTrain,idxTest] = trainingPartitions(numObservations,[0.9 0.1]);
XTrain = data(idxTrain);
TTrain = labels(idxTrain);
XTest = data(idxTest);
TTest = labels(idxTest);
The only change you must make is numClasses = 5;
You must open the LSTM example locally and set that as your current folder in order to get the helper function trainingPartitions.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Image Data Workflows についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!