How can I select 20% of a given data set for training?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a data set that contains 2000 data points
and I would like to select (randomly) 20% of the data for training. How would i do that?
And suppose i wanted the percentage to be a variable? So i can sample any percentage i define?
Thank you!
0 commentaires
Réponses (2)
Rik
le 8 Août 2022
If you want the sample to be repeatable, you will need to specify the state of the random number generator by calling the rng function.
p = randperm(n,k); %returns a row vector containing k unique integers selected randomly from 1 to n.
To calculate k as a function of n and the percentage, you can use the normal arithmatic:
k=round(n*perc/100);
You need to round (or use floor or ceil), because the inputs to randperm must be integer.
0 commentaires
Voir également
Catégories
En savoir plus sur Dimensionality Reduction and Feature Extraction dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!