Alternatives to 'datasample'

10 visualizaciones (últimos 30 días)
Veena Chatti
Veena Chatti el 22 de Ag. de 2020
Comentada: Veena Chatti el 3 de Sept. de 2020
Hi!
I'm looking for an alternative to the datasample function. It's a part of the Statistics & Machine Learning toolbox. Any ideas? I want to be able to sample rows of data from tables and matrices and would like to have the choice of sampling with/without replacement.
Thanks for your ideas!
  5 comentarios
Adam Danz
Adam Danz el 22 de Ag. de 2020
randperm samples without replacement.
To sample with replacement, use randi.
Veena Chatti
Veena Chatti el 26 de Ag. de 2020
Thanks. I think I have it now.

Iniciar sesión para comentar.

Respuesta aceptada

Kiran Felix Robert
Kiran Felix Robert el 26 de Ag. de 2020
Hi Veena,
Yes, randomperm (without replacement) and randi (with replacement) can be used as an alternative.
Furthermore, if the dataset has been converted to either a matrix or an array format, the rows can be sampled without using a loop as shown in the example as follows,
X = rand(50,10); % Assume X is the dataset
SampledRows = X(randi(50,[200,1]),:); % 200 Sample rows (with replacement)
Kiran Felix Robert
  1 comentario
Veena Chatti
Veena Chatti el 3 de Sept. de 2020
Thank you Kiran Felix Robert!

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by