how to partition data into testing and training

10 ビュー (過去 30 日間)
Lucrezia Cester
Lucrezia Cester 2021 年 2 月 7 日
編集済み: Ive J 2021 年 2 月 7 日
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.

回答 (1 件)

Ive J
Ive J 2021 年 2 月 7 日
編集済み: Ive J 2021 年 2 月 7 日
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

カテゴリ

Help Center および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by