- Load the dataset from the “vtl.xlsx” file.
- Review the dataset and ensure it contains columns for time, voltage and class labels.
- Convert your data to a cell array for input to the network.
- Split the data.
- Create an LSTM architecture.
- Set Training options.
- Train the Network.
- Evaluate the Model.
What type of data can be input into the LSTM algorithm?
1 view (last 30 days)
Show older comments
I have voltage data according to time. The time range is from 0 to 460 seconds and samples were taken at irregular intervals e.g 0.2s, 1.3s, 1.7s e.t.c. The data has been labelled with two classes. I want to make a classification algorithm using LSTM which can predict the two classes in my dataset. How do I prepare and input the dataset into my LSTM algorithm?
The dataset is attached.
Thanks in advance.
0 Comments
Answers (1)
Meet
on 5 Sep 2024
Hi Bhavick,
You may follow the steps below to prepare your data as input for the LSTM algorithm,
To begin, please find the code for inputting the data into the LSTM provided below:"
data = readtable('vtl.xlsx');
% Extract voltage and binary response
voltageData = data.voltage;
labels = categorical(data.binaryresponse);
classNames = categories(labels);
% Convert to cell array for input
inputSequences = num2cell(voltageData, 2);
% Split data into training and validation sets
numObservations = numel(inputSequences);
idx = randperm(numObservations);
numTrain = floor(0.8 * numObservations);
% Get the train and validation inputs
trainInputs = inputSequences(idx(1:numTrain));
trainLabels = labels(idx(1:numTrain));
valInputs = inputSequences(idx(numTrain+1:end));
valLabels = labels(idx(numTrain+1:end));
% Define LSTM network architecture
layers = [
sequenceInputLayer(1)
lstmLayer(5, 'OutputMode', 'last')
fullyConnectedLayer(2)
softmaxLayer];
% Set training options
options = trainingOptions('adam', ...
'MaxEpochs', 10, ...
'GradientThreshold', 1, ...
'InitialLearnRate', 0.001, ...
'ValidationData', {valInputs, valLabels}, ...
'Plots', 'training-progress', ...
'Verbose', false);
% Train your network using “trainNetwork” and classify the data using “classify” function
You can refer to the resources below for more information:
0 Comments
See Also
Categories
Find more on Statistics and Machine Learning Toolbox 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!