LSTM classification for days
조회 수: 2 (최근 30일)
이전 댓글 표시
I have 20 control and 20 infected samples. The spectral data of both control and infected samples were collected from day1 to day 15 and saved in excel fromat as day1.xlsx, day2.xlsx........day15.xlsx. For each day the data size is 40*285 (sample*bands). I want to read entire excel data and want to apply LSTM model to classify control and infected samples by considering 15 days as a timepoint. Also I want to know how many days are enough to classify the samples. Any suggestion or related code will be helpful. Thanks!
댓글 수: 3
영준
2025년 1월 16일
Also, when designing the LSTM, it is recommended to be more specific about whether the questions are for each hour of the 15-day period or for the next hour.
채택된 답변
Aastha
2025년 5월 6일
I understand that you would like to train an LSTM model to classify samples as either control or infected, which involves a sequence classification task. You may refer to the steps mentioned below to do so:
1. You will need to decide on the number of days (“numDays”), number of samples (“numSamples”), and the number of features or spectral bands (“numBands”). In MATLAB, you can use the “readmatrix” function to load your data from Excel files and organize it accordingly. You may refer to the MATLAB code snippet below for reference:
numDays = 5;
numSamples = 40;
numBands = 285;
data = zeros(numSamples, numBands, numDays);
for day = 1:numDays
data(:, :, day) = readmatrix(sprintf('day%d.xlsx', day));
end
For any further information on “readmatrix” function, you can refer to the documentation link mentioned below:
2. Rearrange the data to match the LSTM input format using the “permute” function in MATLAB (samples x days x bands).
data = permute(data, [1, 3, 2]); % Resulting size: 40 x 5 x 285
Kindly refer to MathWorks documentation of “permute” function for any queries on it:
3. You can then assign class labels to each sample as illustrated in the MATLAB code snippet below:
labels = [ones(20,1); 2*ones(20,1)];
4. MATLAB expects sequence input as a cell array, with each cell containing a sequence matrix. You can convert your data to this format using the following MATLAB code snippet:
X = cell(numSamples, 1);
for i = 1:numSamples
X{i} = squeeze(data(i, :, :)); % Each sequence: days x bands
end
Y = categorical(labels); % Convert labels to categorical format for classification
You can now proceed to define and train your LSTM network.
For more details on setting up the network architecture and training, you may refer to the MathWorks documentation on sequence classification using LSTM:
Hope this is helpful!
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!