-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsplitData.m
More file actions
57 lines (37 loc) · 1.01 KB
/
Copy pathsplitData.m
File metadata and controls
57 lines (37 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function [trainData, trainLabels, testData, testLabels, devData, devLabels] = splitData(dataMatrix, labelList)
%generates dev and test set with around 1/5 number elements as training set
trainData = dataMatrix; %don't mess up the original data
tempLabels = labelList;
devData = [];
sz = size(trainData, 1);
devSize = round(sz / 5);
devLabels = [];
testLabels = [];
i = 1;
while i <= devSize
rand = randi(sz);
devData = [devData; trainData(rand, :)];
trainData(rand, :) = [];
devLabels = [devLabels; tempLabels(rand)];
tempLabels(rand) = [];
%reduce rand scope by 1 and increment
sz = sz - 1;
i = i + 1;
end
%--------------------------------------------------
testData = [];
sz = size(trainData, 1);
testSize = size(devData, 1);
i = 1;
while i <= testSize
rand = randi(sz);
testData = [testData; trainData(rand, :)];
trainData(rand, :) = [];
testLabels = [testLabels; tempLabels(rand)];
tempLabels(rand) = [];
%reduce rand scope by 1 and increment
sz = sz - 1;
i = i + 1;
end
trainLabels = tempLabels;
end