2020年1月5日星期日

MATLAB: train, test, val inedx number generation function


Function: Randomly draw 1% of integers between [1, N] into val; 1% into test; the rest into train

N = 10000;

A = [1:N]; 
A_temp = A;
val = [];
test = [];

% val
while length(val)<floor(N/100)
    temp = 1+floor(N.*rand(1));
    if ismember(temp,A_temp)
        val = [val, temp];
        A_temp = setdiff(A_temp,temp);
    end
end

% test
while length(test)<floor(N/100)
    temp = 1+floor(N.*rand(1));
    if ismember(temp,A_temp)
        test = [test, temp];
        A_temp = setdiff(A_temp,temp);
    end
end

% train
train = A_temp;

% sort()
test = sort(test);
val = sort(val);
train = sort(train);

没有评论:

发表评论