What type of data can be input into the LSTM algorithm?

1 vue (au cours des 30 derniers jours)
Bhavick Singh
Bhavick Singh le 10 Oct 2021
Réponse apportée : Meet le 5 Sep 2024
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.

Réponses (1)

Meet
Meet le 5 Sep 2024
Hi Bhavick,
You may follow the steps below to prepare your data as input for the LSTM algorithm,
  1. Load the dataset from the “vtl.xlsx” file.
  2. Review the dataset and ensure it contains columns for time, voltage and class labels.
  3. Convert your data to a cell array for input to the network.
  4. Split the data.
  5. Create an LSTM architecture.
  6. Set Training options.
  7. Train the Network.
  8. Evaluate the Model.
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:

Catégories

En savoir plus sur Statistics and Machine Learning Toolbox dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by