-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.m
80 lines (70 loc) · 2.25 KB
/
main.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
function [result ] = main( train_file_path, test_file_path )
%UNTITLED6 Summary of this function goes here
% Detailed explanation goes here
%read Data
train_ds = datastore(train_file_path, 'TreatAsMissing', 'NA');
test_ds = datastore(test_file_path, 'TreatAsMissing', 'NA');
%calculate mean, variace, and pcaCoef
[mean, covariance, ~] = preprocess(train_ds);
[variance, pcaCoef] = process_pca(covariance);
variance = variance';
%size of pcaCoef
K = size(pcaCoef, 2);
%accu
avgAccu = [];
%train data
for k = 1 : K
[ id1, id2, id3, id4, id5 ] = split_id(train_ds);
%5 times test
accu = 0;
%1st
test_index = id1;
train_index = [id2; id3; id4; id5];
%train
w = logistic_regression(pcaCoef, k, mean, variance, train_index, train_ds);
%test
accu = accu + testAccu( pcaCoef, k, w, mean, variance,test_index, train_ds );
%2nd
test_index = id2;
train_index = [id1; id3; id4; id5];
%train
w = logistic_regression(pcaCoef, k, mean, variance, train_index, train_ds);
%test
accu = accu + testAccu( pcaCoef, k, w, mean, variance,test_index, train_ds );
%3rd
test_index = id3;
train_index = [id1; id2; id4; id5];
%train
w = logistic_regression(pcaCoef, k, mean, variance, train_index, train_ds);
%test
accu = accu + testAccu( pcaCoef, k, w, mean, variance,test_index, train_ds );
%4th
test_index = id4;
train_index = [id1; id2; id3; id5];
%train
w = logistic_regression(pcaCoef, k, mean, variance, train_index, train_ds);
%test
accu = accu + testAccu( pcaCoef, k, w, mean, variance,test_index, train_ds );
%5th
test_index = id5;
train_index = [id1; id2; id3; id4];
%train
w = logistic_regression(pcaCoef, k, mean, variance, train_index, train_ds);
%test
accu = accu + testAccu( pcaCoef, k, w, mean, variance,test_index, train_ds );
avgAccu = [avgAccu, accu/5];
end
%choose how many column to choose
[~, k] = max(avgAccu);
k
%train all data
%train
w = logistic_regression(pcaCoef, k, mean, variance, [], train_ds);
%test
[mean, covariance, ~] = preprocess(test_ds);
[variance, pcaCoef] = process_pca(covariance);
variance = variance';
result = finaltest( pcaCoef, k, w, mean, variance, test_ds );
%test
display('end');
end