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

8 views (last 30 days)
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

Answers (1)

Shlok
Shlok on 30 Aug 2024
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:

Categories

Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!