# How to perform stratified 10 fold cross validation for classification in MATLAB?

48 ビュー (過去 30 日間)
Machine Learning Enthusiast 2017 年 7 月 21 日
コメント済み: uma 2022 年 5 月 9 日
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 件のコメント表示非表示 2 件の古いコメント
uma 2022 年 5 月 9 日
what is T_new1

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

### 採用された回答

Tom Lane 2017 年 7 月 25 日
If you have the Statistics and Machine Learning Toolbox, consider the cvpartition function. It can define stratified samples.
##### 3 件のコメント表示非表示 2 件の古いコメント
Olympia Gallou 2021 年 5 月 6 日
How did you solve your problem?

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

### その他の回答 (1 件)

ashik khan 2018 年 11 月 18 日
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

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

### Community Treasure Hunt

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

Start Hunting!

Translated by