Data Partition using CVPartition_ Warning
12 views (last 30 days)
Show older comments
Mustafa Al-Nasser on 25 Jul 2019
Answered: Divya Gaddipati on 5 Aug 2019
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)
h1=Hiddens(1); h2=Hiddens(2); net=fitnet([h1 h2]);
h3=Hiddens(3); net=fitnet([h1 h2 h3]);
% Divide data into k-folds
pred2=; ytest2=; Afold=zeros(kfold,1);
% Neural network start
% Call index of training & testing sets
% Call training & testing inputures and labels
% Set Maximum epochs
% Training model
% Perform testing
tstPerform = perform(net, ytest', pred);
% Get accuracy for each fold
% Store temporary result for each fold
Divya Gaddipati on 5 Aug 2019
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.
More Answers (0)
Find more on Classification Ensembles in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!