how to partition data into testing and training

18 views (last 30 days)
Hello,
I am trying to train a ML network. I am using a matlab function which partitions my data into training and testing set. The problem is that since the classes are arranged likee so:
data=[a a a a a a a a a a a b b b b b b b b b b b c c c c c c c c c c c ] (the a b c in place of the actual classes]
when I use the partition function i get
training [ a a a a a a a b b b b b b b c c c c c c c ]
testing [ a a a a b b b b c c c c ]
while I would want the data to be mized as such :
training [ a b b c b a ...etc
testing [ c b a a /...etc
is there a function to achieve these random splitting?
Thank you very much.

Answers (1)

Ive J
Ive J on 7 Feb 2021
Edited: Ive J on 7 Feb 2021
While I don't see any issues with what MATLAB does nor understand your point, you can use something like this:
test_idx = randperm(numel(data), round(numel(data)*.2)); % 20% for test
train_idx = setdiff(1:numel(data), test_idx); % remaining for training

Categories

Find more on Testing Frameworks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!