MATLAB Answers

Data Partition using CVPartition_ Warning

44 ビュー (過去 30 日間)
Mustafa Al-Nasser
Mustafa Al-Nasser 2019 年 7 月 25 日
回答済み: Divya Gaddipati 2019 年 8 月 5 日
Dear All;
i am trying to use divide my data using Cvpartition with "Kfold" option in order to use for cross valdtion in neural network, i have a function to do that as shown below , it works but it give a warning message and i do not know why it is coming
Warning: One or more folds do not contain points from all the groups.
> In internal.stats.cvpartitionImpl>stra_kfoldcv (line 364)
In internal.stats.cvpartitionImpl/rerandom (line 315)
In internal.stats.cvpartitionInMemoryImpl (line 166)
In cvpartition (line 175)
In jFFNN_REG (line 14)
In NN_Kfold_Regression (line 8)
function [FFNN,Pred,Actual]=jFFNN_REG(input,output,kfold,Hiddens,Maxepochs)
% Layer
if length(Hiddens)==1
h1=Hiddens(1); net=fitnet(h1);
elseif length(Hiddens)==2
h1=Hiddens(1); h2=Hiddens(2); net=fitnet([h1 h2]);
elseif length(Hiddens)==3
h1=Hiddens(1); h2=Hiddens(2);
h3=Hiddens(3); net=fitnet([h1 h2 h3]);
% Divide data into k-folds
% Pre
pred2=[]; ytest2=[]; Afold=zeros(kfold,1);
% Neural network start
for i=1:kfold
% Call index of training & testing sets; testIdx=fold.test(i);
% Call training & testing inputures and labels
xtrain=input(trainIdx,:); ytrain=output(trainIdx);
xtest=input(testIdx,:); ytest=output(testIdx);
% Set Maximum epochs
net.trainParam.epochs= Maxepochs;
% Training model
% Perform testing
% Perfomance
tstPerform = perform(net, ytest', pred);
% Get accuracy for each fold
% Store temporary result for each fold
pred2=[pred2(1:end,:),pred]; ytest2=[ytest2(1:end);ytest];

  0 件のコメント



Divya Gaddipati
Divya Gaddipati 2019 年 8 月 5 日
c = cvpartition(n,'KFold',k)
The above syntax of the function randomly splits the “n” observations into “k” disjoint sets of roughly equal size. Hence, it doesn’t ensure if all the “k” sets include samples corresponding to all the classes. If your dataset is highly imbalanced, there is a possibility that some of the sets might not contain samples corresponding to the minority class.
c = cvpartition(group,'KFold',k,'Stratify',true)
While, the above syntax of the function ensures that each of the “k” sets contain approximately the same percentage of samples for each class as the complete set.
In case of large imbalance in the distribution of target classes, it is recommended to use stratified sampling to ensure that relative class frequencies are approximately preserved in each train and validation fold.
For more syntaxes of this function, refer to this link.

  0 件のコメント


その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by