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

8 vues (au cours des 30 derniers jours)
Abdirizaak Khaliif
Abdirizaak Khaliif le 21 Jan 2023
Réponse apportée : Shlok le 30 Août 2024
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

Réponses (1)

Shlok
Shlok le 30 Août 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:

Catégories

En savoir plus sur Statistics and Machine Learning Toolbox dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by