How can I make the input data and target data have same samples for ANN training

8 次查看(过去 30 天)
I have gathered data as an input and the code is supposed to be my target data but unfortunatley I don't know how to make the samples same for input and target data

回答(1 个)

Shlok
Shlok 2024-8-30
Hi Abdirizaak,
I understand that you want to extract random samples from your collected data and you want to ensure that the corresponding target data remains consistent with input data.
Follow the following steps to achieve the same:
  • Combine your input data and target data into a cell array. This way, when you sample from the input data, the target data will automatically remain aligned. For example:
combined_data = [input_data, target_data];
  • Use random sampling to select a subset of the combined data. This will ensure that both the input and target data are sampled together, maintaining consistency.
num_samples = 50; % For example
% Generate random indices for sampling
random_indices = randperm(size(combined_data, 1), num_samples);
% Sample the combined data
sampled_data = combined_data(random_indices, :);
  • After sampling, separate the input and target data back into their respective variables.
sampled_input_data = sampled_data(:, 1:end-1); % All columns except the last one
sampled_target_data = sampled_data(:, end); % Last column
By following these steps, you can randomly sample your input data while keeping the target data consistent.
To know more about “randperm” function used for sampling, checkout the following MathWorks Documentation link:

类别

Help CenterFile Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by