LSTM classification for days
3 次查看(过去 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!