-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsplit_scale.m
More file actions
32 lines (29 loc) · 1.42 KB
/
split_scale.m
File metadata and controls
32 lines (29 loc) · 1.42 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
%% Split - Preprocess Data
function [trnData,chkData,tstData] = split_scale(data,preproc)
idx=randperm(length(data));
trnIdx=idx(1:round(length(idx)*0.6));
chkIdx=idx(round(length(idx)*0.6)+1:round(length(idx)*0.8));
tstIdx=idx(round(length(idx)*0.8)+1:end);
trnX=data(trnIdx,1:end-1);
chkX=data(chkIdx,1:end-1);
tstX=data(tstIdx,1:end-1);
switch preproc
case 1 %Normalization to unit hypercube
xmin=min(trnX,[],1);
xmax=max(trnX,[],1);
trnX=(trnX-repmat(xmin,[length(trnX) 1]))./(repmat(xmax,[length(trnX) 1])-repmat(xmin,[length(trnX) 1]));
chkX=(chkX-repmat(xmin,[length(chkX) 1]))./(repmat(xmax,[length(chkX) 1])-repmat(xmin,[length(chkX) 1]));
tstX=(tstX-repmat(xmin,[length(tstX) 1]))./(repmat(xmax,[length(tstX) 1])-repmat(xmin,[length(tstX) 1]));
case 2 %Standardization to zero mean - unit variance
mu=mean(data,1);
sig=std(data,1);
trnX=(trnX-repmat(mu,[length(trnX) 1]))./repmat(sig,[length(trnX) 1]);
chkX=(trnX-repmat(mu,[length(chkX) 1]))./repmat(sig,[length(chkX) 1]);
tstX=(trnX-repmat(mu,[length(tstX) 1]))./repmat(sig,[length(tstX) 1]);
otherwise
disp('Not appropriate choice.')
end
trnData=[trnX data(trnIdx,end)];
chkData=[chkX data(chkIdx,end)];
tstData=[tstX data(tstIdx,end)];
end