How to manually cross-validate self-partitioned array (e.g. cross-validate array a to array b)

Dear MathWorks Community,
This is my first time posting in the community. The condition of my dataset is as followed:
%Data X
X = [101 102 103 104 105 106 107 108 109; 3 3 3 4 4 4 5 5 5; 65 65 65 60 60 60 20 20 20; -1 -1 -1 0 0 0 -2 -2 -2; -2 -2 -2 -1 -1 -1 0 0 0; 1.1 2.1 3.2 2.1 3.1 2.2 3.2 4.5 6.2].'
%First column = the 'n' th number of data.
%Second column = the 'm' th observation
%Third column = the 'ID' of subject
%Fourth to fifth column = annotated value of A, B (response variable)
%Sixth column to nth column = raw value/observed numerical value (predictor variable)
The data partition is done based on the 'ID' (third column) value so that for e.g
training dataset will be cross validated specifically by partitioning all ID=65, 60 as the training set and ID=20 as the test set.
I tried using cvpartition but could not find how to do partition based on the condition above.
So I manually do the partition by creating X0_train as the train matrix, X0_test as the test matrix based on the 'ID' randomly.
%Unique ID
X0_unique = unique(X(:,3));
% Randomization X
[X0m, X0n] = size(X0_unique);
X0_testn = round(X0m/3,0);
X0_testn1 = randsample(X(:,3),X0_testn);
X0_test = X(ismember([X(:,3)],X0_testn1),:);
X0_idtest = X0_test(:,1);
X0_idtrain = setdiff(X(:,1),X0_idtest);
X0_train = X(ismember([X(:,1)],X0_idtrain),:);
Mdl = fitrsvm(X(:,6:end),X(:,4),'Standardize',true, 'OptimizeHyperparameters','auto','KernelFunction','rbf')
Now my problem is I could not find ways to manually cross-validate X0_train to X0_test for kfold=10
I know if we set the 'OptimizeHyperparameters' manually we can determine the cross-validation kfold=10 but still not sure how to specifically determine the cross-validation to be done in such manner.
Your help would be very much appreciated. Please kindly guide me.

Answers (0)

Products

Release

R2021b

Asked:

on 22 Jun 2022

Edited:

on 22 Jun 2022

Community Treasure Hunt

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

Start Hunting!