How to perform stratified 10 fold cross validation for classification in MATLAB?
Ältere Kommentare anzeigen
My implementation of usual K-fold cross-validation is pretty much like:
K = 10;
CrossValIndices = crossvalind('Kfold', size(B,2), K);
for i = 1: K
display(['Cross validation, folds ' num2str(i)])
IndicesI = CrossValIndices==i;
TempInd = CrossValIndices;
TempInd(IndicesI) = [];
xTraining = B(:, CrossValIndices~=i);
tTrain = T_new1(:, CrossValIndices~=i);
xTest = B(:, CrossValIndices ==i);
tTest = T_new1(:, CrossValIndices ==i);
end
But To ensure that the training, testing, and validating dataset have similar proportions of classes (e.g., 20 classes).I want use stratified sampling technique.Basic purpose is to avoid class imbalance problem.I know about SMOTE technique but i want to apply this one.
3 Kommentare
Leyre Azcárate Bescós
am 27 Aug. 2020
What is B?
Leyre Azcárate Bescós
am 27 Aug. 2020
And T_new1?
uma
am 9 Mai 2022
what is T_new1
Akzeptierte Antwort
Weitere Antworten (1)
ashik khan
am 18 Nov. 2018
1 Stimme
What are the value of B and T_new1 ??
K = 10;
CrossValIndices = crossvalind('Kfold', size(B,2), K);
for i = 1: K
display(['Cross validation, folds ' num2str(i)])
IndicesI = CrossValIndices==i;
TempInd = CrossValIndices;
TempInd(IndicesI) = [];
xTraining = B(:, CrossValIndices~=i);
tTrain = T_new1(:, CrossValIndices~=i);
xTest = B(:, CrossValIndices ==i);
tTest = T_new1(:, CrossValIndices ==i);
end
Kategorien
Mehr zu Get Started with Statistics and Machine Learning Toolbox finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!