USING LSTM TO CLASSIFY DATA
이전 댓글 표시
Please see my code below
% Step 1: Load the data from the Excel file
data = readmatrix('LSTMdataIn.xlsx');
% Step 2: Create labels
labels = [ones(200, 1); 2*ones(200, 1); 3*ones(200, 1); 4*ones(200, 1); 5*ones(200, 1)];
% Step 3: Reshape the data
numTimeSteps = 100;
numFeatures = 1;
reshapedData = reshape(data', numFeatures, numTimeSteps, []);
% Step 4: Split the data into training and testing sets
cv = cvpartition(labels, 'HoldOut', 0.2);
trainIdx = training(cv);
testIdx = test(cv);
XTrain = reshapedData(:, :, trainIdx);
YTrain = labels(trainIdx);
XTest = reshapedData(:, :, testIdx);
YTest = labels(testIdx);
% Step 5: Create and train the LSTM network
numHiddenUnits = 100;
layers = [ ...
sequenceInputLayer(100)
lstmLayer(numHiddenUnits)
fullyConnectedLayer(5)
softmaxLayer
classificationLayer];
options = trainingOptions('adam', 'MaxEpochs', 10, 'MiniBatchSize', 32);
net = trainNetwork(XTrain, categorical(YTrain), layers, options);
% Step 6: Evaluate the trained network
YTestPred = classify(net, XTest);
accuracy = sum(YTestPred == categorical(YTest)) / numel(YTest);
I get the following error
The training sequences are of feature dimension 1 100 but the input layer expects sequences of feature dimension 100.
댓글 수: 1
Matt J
2024년 6월 10일
This question looks the same as,
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!