-
Notifications
You must be signed in to change notification settings - Fork 0
/
pcaCox.m
43 lines (35 loc) · 1.01 KB
/
pcaCox.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
clear all;
prepareData
%% constants
iter = 1;
K = 3;
c = zeros(iter, 1);
m = size(X, 1);
F = floor(m / K);
cursor = 0;
cindex_train = 0;
cindex_test = 0;
while (cursor < F * K)
starti = cursor + 1;
if (m - cursor < K)
endi = m;
else
endi = cursor + F;
end
X_test = X(starti:endi, :);
y_test = T(starti:endi);
c_test = C(starti:endi);
X_train = X([1:starti - 1 endi + 1:m], :);
y_train = T([1:starti - 1 endi + 1:m]);
c_train = C([1:starti - 1 endi + 1:m]);
[coeff,X_train_red] = pca(X_train, 'NumComponents', 20);
%% cox coefficients
[b2, logl, H, stats] = coxphfit(X_train_red, y_train);
X_test_reduced = X_test * coeff;
cindex_train = cindex_train + cIndex(b2, X_train_red, y_train, c_train);
cindex_test = cindex_test + cIndex(b2, X_test_reduced, y_test, c_test);
cursor = cursor + F;
%perf = mse(autoenc1, autoenc1(D'), D', 'normalization', 'percent')
end
cindex_test = cindex_test / K;
cindex_train = cindex_train / K;