how to partition data into testing and training

10 visualizzazioni (ultimi 30 giorni)
Lucrezia Cester
Lucrezia Cester il 7 Feb 2021
Modificato: Ive J il 7 Feb 2021
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.

Risposte (1)

Ive J
Ive J il 7 Feb 2021
Modificato: Ive J il 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

Categorie

Scopri di più su Statistics and Machine Learning Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by