How can I do a 80-20 split on datasets to obtain training and test datasets?

50 ビュー (過去 30 日間)
Chidiebere Ike
Chidiebere Ike 2018 年 3 月 15 日
コメント済み: Prasobhkumar P. P. 2020 年 11 月 7 日
I tried [training, test] = partition (faceDatabase, [0.8, 0.2]); but it gives me error. Can anyone help? Are there ways to do this manually? I can't find a function for this!
  2 件のコメント
Akira Agata
Akira Agata 2018 年 3 月 15 日
How about using cvpartition ?
Chidiebere Ike
Chidiebere Ike 2018 年 3 月 15 日
OK. Thanks for your response. I will give it a try. But can this be achieved via a for loop??

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

採用された回答

KSSV
KSSV 2018 年 3 月 15 日
Let P and T be your input and target sets.
PD = 0.80 ; % percentage 80%
Ptrain = P(1:round(PD*length(T)),:) ; Ttrain = T(1:round(PD*length(T))) ;
Ptest = P(round(PD*length(T)):end,:) ;Ttest = T(round(PD*length(T)):end) ;
  2 件のコメント
Chidiebere Ike
Chidiebere Ike 2018 年 3 月 15 日
編集済み: Chidiebere Ike 2018 年 3 月 15 日
I tried the code, it says "undefined function or variable T"... I will appreciate if you describe the letter P, T and length ... How do I resolve this. ?
Prasobhkumar P. P.
Prasobhkumar P. P. 2020 年 11 月 7 日
P and T corresponds to each labels (or categories)

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

その他の回答 (2 件)

Akira Agata
Akira Agata 2018 年 3 月 15 日
編集済み: Akira Agata 2018 年 3 月 15 日
If you want to randomly select 80% of your data as training dataset, please try following:
PD = 0.80 ; % percentage 80%
% Let P be your N-by-M input dataset
% Solution-1 (need Statistics & ML Toolbox)
cv = cvpartition(size(P,1),'HoldOut',PD);
Ptrain = P(cv.training,:);
Ptest = P(cv.test,:);
Another possible solution:
% Solution-2 (using basic MATLAB function)
N = size(P,1);
idx = randperm(N);
Ptrain = P(idx(1:round(N*PD)),:);
Ptest = P(idx(round(N*PD)+1:end),:);
  1 件のコメント
Chidiebere Ike
Chidiebere Ike 2018 年 3 月 15 日
Solution 1 gives an error message.. Error in cvpartition CV.Impl = internal.stats.cvpartitionInMemoryImpl(varargin{:});

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


Munshida P
Munshida P 2020 年 1 月 14 日
This will help you.
[training,test] = partition(faceDatabase,[0.8 0.2]);

カテゴリ

Help Center および File ExchangeGet Started with Statistics 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