Best way to split data into random partitions?

I am new to Matlab and still a student. For an assignment, I am stuck on this part.
Create 5 random partitions of the data, splitting each of the classes into 60% training and 40% testing.
I have two classes, Class One and Class Two.
How would I be able to do this?
classOne and classTwo is 10000x2 double histogram

 採用された回答

Cris LaPierre
Cris LaPierre 2019 年 1 月 12 日
編集済み: Cris LaPierre 2019 年 1 月 12 日

2 投票

I would use the dividerand function in the Deep Learning Toolbox.
For example
[trainInd,valInd,testInd] = dividerand(3000,0.6,0.2,0.2);
Just set the validation percentage to 0 if you don't need it.

5 件のコメント

G. Nardi
G. Nardi 2019 年 1 月 12 日
Can you tell me what the values mean in your example? 30000, .6 (I am assuming is the training and), .2,.2)
Cris LaPierre
Cris LaPierre 2019 年 1 月 12 日
I assume you've looked at the documentation page, so I won't duplicate info from there.
This function returns indices. Indices can then be used to select data for training, validation or testing.
From what you mention, let's say ClassOne is 10000x2. I want 60% (6000 rows) for training and 40% (4000 rows) for testing. I'd do this
[trainInd,~,testInd] = dividerand(length(ClassOne),0.6,0,0.4);
Now when you need your training data, you would use
ClassOne(trainInd,:)
and when you need you testing data, you would use
ClassOne(testInd,:)
dividerand creates groups randomly, so you would get different groups each time you called it.
G. Nardi
G. Nardi 2019 年 1 月 12 日
i don't have that toolbox.
David Goodmanson
David Goodmanson 2019 年 1 月 12 日
HI Masaki,
Neither do I, but you can use somthing more basic like RandInd = randperm(n), which creates a vector containing a random arrangement of the numbers 1:n. Then you can take the first 60% (or whatever) of RandInd to be TrainInd, etc. and proceed from there.
G. Nardi
G. Nardi 2019 年 1 月 12 日
thanks! i appreciate it.

サインインしてコメントする。

その他の回答 (0 件)

製品

リリース

R2018b

タグ

質問済み:

2019 年 1 月 11 日

コメント済み:

2019 年 1 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by