Specify indices of cvpartition
조회 수: 2 (최근 30일)
이전 댓글 표시
I want to manually specify the indices in cvpartition for leave-one-out cross validation with 5 subjects. Right now the data is split into 5 equal parts if I set "KFold" to 5.
train = [1:50];
cvpt = cvpartition(train,"KFold",5)
K-fold cross validation partition
NumObservations: 50
NumTestSets: 5
TrainSize: 40 40 40 40 40
TestSize: 10 10 10 10 10
Now I want to manually specify which indices are used for training and which for testing. Lets say the indices of my 5 train and test sets are:
Test1_idx = [1:8]; Train1_idx = [9:50];
Test2_idx = [9:21]; Train2_idx = [1:8 22:50];
Test3_idx = [22:31]; Train3_idx = [1:21 32:50];
Test4_idx = [32:44]; Train4_idx = [1:31 45:50];
Test5_idx = [45:50]; Train5_idx = [1:44];
How can I specify this in Matlab before I fit machine learning model?
The cvpt should then look like this:
NumObservations: 50
NumTestSets: 5
TrainSize: 42 37 40 37 44
TestSize: 8 13 10 13 6
댓글 수: 0
답변 (1개)
Drew
2024년 1월 26일
As of R2023b, users can manually specify the indices in a cvpartition with the syntax
c = cvpartition("CustomPartition",testSets)
The details, including the possible formats for the "testSets" specification, are in the R2023b+ cvpartition doc https://www.mathworks.com/help/stats/cvpartition.html. This new feature is also mentioned in the R2023b SMLT release notes at https://www.mathworks.com/help/stats/release-notes.html.
If this answer helps you, please remember to accept the answer.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!