Specify indices of cvpartition

2 次查看(过去 30 天)
Dylan den Hartog
Dylan den Hartog 2021-10-26
回答: Drew 2024-1-26
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

回答(1 个)

Drew
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.

类别

Help CenterFile Exchange 中查找有关 Model Building and Assessment 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by