How to use cross validation/ leave one out in algorithm
61 ビュー (過去 30 日間)
古いコメントを表示
How can I use cross validation/Leave one out in following example https://in.mathworks.com/help/deeplearning/ug/train-stacked-autoencoders-for-image-classification.html
0 件のコメント
回答 (1 件)
Pranav Verma
2020 年 8 月 12 日
Hi Chhavi,
The cvpartition(group,'KFold',k) function with k=n creates a random partition for leave-one-out cross-validation on n observations. Below example demonstrates the aforementioned function,
load('fisheriris');
CVO = cvpartition(species,'k',150); %number of observations 'n' = 150
err = zeros(CVO.NumTestSets,1);
for i = 1:CVO.NumTestSets
trIdx = CVO.training(i);
teIdx = CVO.test(i);
ytest = classify(meas(teIdx,:),meas(trIdx,:),...
species(trIdx,:));
err(i) = sum(~strcmp(ytest,species(teIdx)));
end
cvErr = sum(err)/sum(CVO.TestSize);
Alternatively, you can use cvpartition(n,'LeaveOut') leave-one-out cross-validation.
For further information about the cross-validation in MATLAB, please refer to the link: https://www.mathworks.com/help/stats/cvpartition.html
1 件のコメント
Chhavi Bharti
2021 年 2 月 5 日
編集済み: Chhavi Bharti
2021 年 2 月 5 日
@Pranav Verma Hi pranav I tried this code. But this is randomly doing the partition. How cound i get an index for tested data?
fold=cvpartition(label,'LeaveOut');
cp=classperf(label);
confmat=0;
for k=1:size(label,2)
trainIdx=fold.training(k); testIdx=fold.test(k);
xtrainc=imgs(trainIdx); ytrainc=label(trainIdx);
xtestc=imgs(testIdx); ytestc=label(testIdx);
xTrainImages=xtrainc';
tTrain=ytrainc;
xTestImages=xtestc';
tTest=ytestc;
%%DNN model
[c,cm,ind,per]=confusion(tTest,y); % y is output of DNN model
end
参考
カテゴリ
Help Center および File Exchange で Gaussian Process Regression についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!