-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcv_ens_platform.m
62 lines (50 loc) · 2.15 KB
/
cv_ens_platform.m
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
55
56
57
58
59
60
61
62
%Program for CSC522 course project: Precipitation prediction of
%Northwestern United States
%run after day_data_preprocessing
%10-fold cross validation model selection
feature_matrix = correlation_matrix;
edges = [0, 0.1, 2.5, 10, 25, 50, 100, 400];
%mod_sel_dis_data = discretize(mod_sel_data, edges);
tloss = zeros(length(lon), length(lat));
[~, ~, d, ~] = size(feature_matrix);
[lo, la, dat] = size(mod_sel_data);
%mypool = parpool(4);
paroptions = statset('UseParallel',true);
%nens = templateEnsemble('Method', 'AdaBoostM2');
%train_data = [];
%for i=1:dat
% tp = mod_sel_data(:, :, i);
% train_data = [train_data, tp(~no_detect)];
%end
%train_data = train_data';
parfor m=1:lo
for n=1:la
if (~no_detect(m, n))
%prepare training data (including cv data)
cur_cost_matrix = cost_matrix;
train_labels = reshape(mod_sel_labels(m, n, :), [length(mod_sel_labels), 1]);
lb = [sum(train_labels==1), sum(train_labels==2), sum(train_labels==3), sum(train_labels==4), sum(train_labels==5)];
for i=0:(length(lb)-1)
tar = length(lb)-i;
if (lb(tar)==0)
cur_cost_matrix(tar, :) = [];
cur_cost_matrix(:, tar) = [];
end
end
train_data = [];
for j=1:(d-1)
cm = feature_matrix(m, n, j, 2);
cn = feature_matrix(m, n, j, 3);
train_data = [train_data; mod_sel_data(cm, cn, :)];
end
train_data = reshape(train_data, [(d-1), length(mod_sel_data)]);
%train_data = [mean(train_data, 1); max(train_data, [], 1); min(train_data, [], 1); std(train_data, 0, 1)];
train_data = train_data';
ensmd = fitcensemble(train_data, train_labels, 'Method', 'AdaBoostM2','Cost', cur_cost_matrix, 'CrossVal', 'on', 'KFold', 5);
cl = kfoldLoss(ensmd, 'LossFun', 'mincost');
disp(cl);
tloss(m, n) = tloss(m, n)+cl;
end
end
end
%delete mypool