How to set the seed of cvpartition
    조회 수: 6 (최근 30일)
  
       이전 댓글 표시
    
I would like to partition a set of training data the same way (randomly) over different iterations of the code. How can I set the seed for the random index choice of cvpartition
댓글 수: 0
답변 (1개)
  Akira Agata
    
      
 2018년 4월 26일
        Please add rng function just before cvpartition to set seed of the random number generation. Here is an simple example:
n = 10000;
k = 5;
seed = 100;
rng(seed);
c1 = cvpartition(n,'KFold',k);
rng(seed);
c2 = cvpartition(n,'KFold',k);
Then, c1 and c2 becomes the same.
>> isequal(c1,c2)
ans =
logical
 1
But, to partition a set of training data the same way over different iterations, you may not need to set the seed for each iteration, like:
c0 = cvpartition(n,'KFold',k);
for Iteration = 1:M
  for kk = 1:5
    trainSet = Data(c0.training(kk),:);
    testSet  = Data(c0.test(kk),:);
    ... (Some process for each train/test dataset)
  end
  ... (Some process for each iteration)
end
댓글 수: 0
참고 항목
카테고리
				Help Center 및 File Exchange에서 Discriminant Analysis에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

