|
• SRS w/o Replacement of Train, Test Sets in MATLAB
Again, let 'A' be the data array, with examples in rows and variables in columns. Assume that 1000 samples are desired, for, perhaps, training as opposed to testing. Try this:
% Number of samples to draw
TrainN = 1000;
% Generate scrambled index of 'A'
RandIndex = randperm(size(A,1))';
% Get Training rows only
TrainRows = RandIndex(1:TrainN);
% Get Test rows only
TestRows = RandIndex(TrainN+1:end);
Obviously, this can easily be extended to Train, Test and Validation sets, etc., but if one requires selection for things like k-fold cross-validation, it is probably easier to use something like:
% Generate 10-way partition of 'A'
kFoldGroupIndex = ceil(10 * rand(size(A,1),1));
Now, there are (approximately) an equal number of integers 1, 2, ... 10, making train/test in k-fold cross-validation easy.
-Predictor
http://will.dwinnell.com
|