matlab - Splitting data using randperm -


i have

dataset=[6 7;          5 4;          9 8;          1 2;          9 8;          4 5;          1 2;          3 4;          8 7;          6 2]  

can random select 90% of data training , remaining (10%) test set repeat split 10 times.

i.e

training = [6 7;             5 4;             9 8;             1 2;             9 8;             1 2;             3 4;             8 7;             6 2]   test= [4 5] 

i wrote code

num_points = size(x,2);  split_point = round(num_points*0.7); 

to split data can't obtain result

dataset=[6 7;          5 4;          9 8;          1 2;          9 8;          4 5;          1 2;          3 4;          8 7;          6 2]  

randomly re-order dataset using randperm:

n = size(dataset,1); data_rand = dataset(randperm(n),:) 

then pull out different 10% each time:

m = ceil(n/10); group = 1; k = 1:m:n-m     test{group} = data_rand(k:k+m-1,:)     train{group} = [data_rand(1:k-1,:); data_rand(k+m:end,:)];     group = group + 1; end 

but suggest read cross validation in matlab has lot of built-in functionality this.


Comments