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

1 回表示 (過去 30 日間)
Bhavick Singh
Bhavick Singh 2021 年 10 月 10 日
回答済み: Meet 2024 年 9 月 5 日
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.

回答 (1 件)

Meet
Meet 2024 年 9 月 5 日
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:

カテゴリ

Help Center および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by