Predicting Mortality of ICU Patients: The PhysioNet/Computing in Cardiology Challenge 2012 1.0.0
(12,551 bytes)
function DATA=PCA_classificator(IHD,time_series_names,MEAN_DATA_24,MEAN_DATA_48,DESCRIPTORS,des_names)
X=[MEAN_DATA_24 MEAN_DATA_48 ];
%X=[X1];
%X=[X];
AGE_a=DESCRIPTORS(:,strcmp(des_names,'Age'));
Gender_a=DESCRIPTORS(:,strcmp(des_names,'Gender'));
ICUTYPE_a=[DESCRIPTORS(:,strcmp(des_names,'ICUType'))];
ICUTYPE_t=ICUTYPE_a;
ICUTYPE_a(ICUTYPE_t==1)=2;
ICUTYPE_a(ICUTYPE_t==2)=4;
ICUTYPE_a(ICUTYPE_t==3)=1;
ICUTYPE_a(ICUTYPE_t==4)=3;
X=[AGE_a ICUTYPE_a X];
%if des{:,strcmp(des_names,'Gender')}==0
%X_new_rec=zeros(size(X));
savefile='gender0.mat';
savefile='gender0_60.mat';
load(savefile,'N2','PHAT_all','best_th','A','S','Mu','V', 'CV', 'HP', 'LC','N','pc1','mu','sigma','B');
% S_new=calc_S_new_data(X',A,V,Mu,N,CV);
X_new_rec =( repmat(Mu,1,size(S,2)) + (A*S))';
% mu1=Mu;
sigma0 = sigma;
sigma0(sigma0==0) = 1;
z = bsxfun(@minus,X_new_rec', mu');
z = bsxfun(@rdivide, z, sigma0');
x_in=(pinv(pc1)*z)';
X(Gender_a==0,:)=x_in(Gender_a==0,:);
% X(Gender_a==0,:)=x_in;
N1=N2;
%X_reconstructed=zeros(size(X));
% X_reconstructed(Gender_a==0,:)=X_new_rec(Gender_a==0,:);
% X_reconstructed(Gender_a==0,:)=X_new_rec;
% x_in=x_in(1:N2);
%elseif des{:,strcmp(des_names,'Gender')}==1
savefile='gender1.mat';
savefile='gender1_60.mat';
load(savefile,'N2','PHAT_all','best_th','A','S','Mu','V', 'CV', 'HP', 'LC','N','pc1','mu','sigma','B');
% mu2=Mu;
% plot(mu1)
% hold on
% plot(mu2)
% S_new=calc_S_new_data(X(Gender_a==1,:),A,V,Mu,N,CV);
X_new_rec =( repmat(Mu,1,size(S,2)) + A*S)';
sigma0 = sigma;
sigma0(sigma0==0) = 1;
z = bsxfun(@minus,X_new_rec', mu');
z = bsxfun(@rdivide, z, sigma0');
x_in=(pinv(pc1)*z)';
X(Gender_a==1,:)=x_in(Gender_a==1,:);
% X(Gender_a==1,:)=x_in;
% X_reconstructed(Gender_a==1,:)=X_new_rec(Gender_a==1,:);
%X_reconstructed(Gender_a==1,:)=X_new_rec;
% data1=X_reconstructed(Gender_a==0,3:39);
% data2=X_reconstructed(Gender_a==0,40:76);
% S0=analyze_params(data1,data2,IHD(Gender_a==0),time_series_names);
%
% X_classify=zeros(size(data1,1),[]);
% add_idx=1;
%
% for param_idx=1:size(S0,1)
%
% if S0(param_idx,1)==1
% X_classify(:,add_idx)=data1(:,param_idx);
% add_idx=add_idx+1;
% elseif S0(param_idx,2)==1
% X_classify(:,add_idx)=data2(:,param_idx);
% add_idx=add_idx+1;
% elseif S0(param_idx,3)==1
% X_classify(:,add_idx:add_idx+1)=[data1(:,param_idx) data2(:,param_idx)];
% add_idx=add_idx+2;
% elseif S0(param_idx,4)==1
% X_classify(:,add_idx:add_idx+1)=[data1(:,param_idx) abs(data2(:,param_idx))];
% add_idx=add_idx+2;
% elseif S0(param_idx,5)==1
% X_classify(:,add_idx)=(data1(:,param_idx)+data2(:,param_idx))./2;
% add_idx=add_idx+1;
% else
% % pad parameter
% end
% end
%
% for param_idx=1:size(S0,1)
%
% if max(S0(param_idx,:))==1
% X_classify(:,add_idx:add_idx+1)=[data1(:,param_idx) data2(:,param_idx)];
% add_idx=add_idx+2;
% else
% % pad parameter
% end
% end
%
% X_classify=[AGE_a(Gender_a==0) ICUTYPE_a(Gender_a==0) X_classify];
% [best_th1,max_score_1,D0] = opt_th(X_classify,IHD(Gender_a==0));
%
%
% data1=X_reconstructed(Gender_a==1,3:39);
% data2=X_reconstructed(Gender_a==1,40:76);
% S1=analyze_params(data1,data2,IHD(Gender_a==1),time_series_names);
%
% X_classify=zeros(size(data1,1),[]);
% add_idx=1;
%
% for param_idx=1:size(S1,1)
%
% if S1(param_idx,1)==1
% X_classify(:,add_idx)=data1(:,param_idx);
% add_idx=add_idx+1;
% elseif S1(param_idx,2)==1
% X_classify(:,add_idx)=data2(:,param_idx);
% add_idx=add_idx+1;
% elseif S1(param_idx,3)==1
% X_classify(:,add_idx:add_idx+1)=[data1(:,param_idx) data2(:,param_idx)];
% add_idx=add_idx+2;
% elseif S1(param_idx,4)==1
% X_classify(:,add_idx:add_idx+1)=[data1(:,param_idx) abs(data2(:,param_idx))];
% add_idx=add_idx+2;
% elseif S1(param_idx,5)==1
% X_classify(:,add_idx)=(data1(:,param_idx)+data2(:,param_idx))./2;
% add_idx=add_idx+1;
% else
% % pad parameter
% end
% end
%
% for param_idx=1:size(S0,1)
%
% if max(S1(param_idx,:))==1
% X_classify(:,add_idx:add_idx+1)=[data1(:,param_idx) data2(:,param_idx)];
% add_idx=add_idx+2;
% else
% % pad parameter
% end
% end
%
% X_classify=[AGE_a(Gender_a==1) ICUTYPE_a(Gender_a==1) X_classify];
% [best_th1,max_score_1,D0] = opt_th(X_classify,IHD(Gender_a==1));
%
%
% data1=X_reconstructed(:,3:39);
% data2=X_reconstructed(:,40:76);
% S=analyze_params(data1,data2,IHD,time_series_names);
% X_classify=zeros(4000,[]);
% add_idx=1;
%
% for param_idx=1:size(S,1)
%
% if S(param_idx,1)==1
% X_classify(:,add_idx)=data1(:,param_idx);
% add_idx=add_idx+1;
% elseif S(param_idx,2)==1
% X_classify(:,add_idx)=data2(:,param_idx);
% add_idx=add_idx+1;
% elseif S(param_idx,3)==1
% X_classify(:,add_idx:add_idx+1)=[data1(:,param_idx) data2(:,param_idx)];
% add_idx=add_idx+2;
% elseif S(param_idx,4)==1
% X_classify(:,add_idx:add_idx+1)=[data1(:,param_idx) abs(data2(:,param_idx))];
% add_idx=add_idx+2;
% elseif S(param_idx,5)==1
% X_classify(:,add_idx)=(data1(:,param_idx)+data2(:,param_idx))./2;
% add_idx=add_idx+1;
% else
% % pad parameter
% end
% end
%
% for param_idx=1:size(S,1)
%
% if max(S(param_idx,:))==1
% X_classify(:,add_idx:add_idx+1)=[data1(:,param_idx) data2(:,param_idx)];
% add_idx=add_idx+2;
% else
% % pad parameter
% end
% end
%
% X_classify=[AGE_a ICUTYPE_a X_classify];
% % plot(data1(100,:),'r');hold on;plot(data2(100,:),'g')
% [best_th1,max_score_1,D0] = opt_th(X_classify(Gender_a==0,:),IHD(Gender_a==0));
% [best_th2,max_score_2,D1] = opt_th(X_classify(Gender_a==1,:),IHD(Gender_a==1));
%
% DATA(:,1)=0;
% DATA(Gender_a==0,2)=D0(:,2);
% DATA(Gender_a==1,2)=D1(:,2);
% DATA(Gender_a==0,3)=D0(:,3);
% DATA(Gender_a==1,3)=D1(:,3);
% return
% % [best_th0,max_score_0,D] = opt_th(X_classify,IHD);
% % pause(.1)
%
%
%0.2708
%X=[R(:,~strcmp(time_series_names,'MechVent'))];
%0.277
% X=[R(:,strcmp(time_series_names,'TroponinT'))];
% X=[R(:,strcmp(time_series_names,'TroponinI')) X];
% X=[R(:,strcmp(time_series_names,'RespRate')) X];
% X=[R(:,strcmp(time_series_names,'Mg')) X];
% X=[R(:,strcmp(time_series_names,'Lactate')) X];
% X=[R(:,strcmp(time_series_names,'K')) X];
% X=[R(:,strcmp(time_series_names,'FiO2')) X];
% X=[R(:,strcmp(time_series_names,'Bilirubin')) X];
% X=[R(:,strcmp(time_series_names,'AST')) X];
% X=[R(:,strcmp(time_series_names,'ALT')) X];
% X=[R(:,strcmp(time_series_names,'ALP')) X];
% X=[R(:,strcmp(time_series_names,'Albumin')) X];
%
% % % max_N=min(N1,N2);
% % % X=X(:,1:max_N);
% % %
% % % X_orig=X;
% % %
% % % scores=zeros(max_N,3);
% % %
% % % for idx=10:max_N
% % %
% % % X=X_orig(:,1:idx);
% % % %[best_th0,max_score_0,D] = opt_th(X,IHD);
% % % %
% % % % [best_th1,max_score_1,D0] = opt_th(X(Gender_a==0,:),IHD(Gender_a==0));
% % % % [best_th2,max_score_2,D1] = opt_th(X(Gender_a==1,:),IHD(Gender_a==1));
% % %
% % % [best_th0,max_score_0,D] = opt_th_valid(X,IHD);
% % % [best_th1,max_score_1,D0] = opt_th_valid(X(Gender_a==0,:),IHD(Gender_a==0));
% % % [best_th2,max_score_2,D1] = opt_th_valid(X(Gender_a==1,:),IHD(Gender_a==1));
% % %
% % % scores(idx,:)=[max_score_1 max_score_2 max_score_0];
% % % end
% % %
% % % figure(1)
% % % plot(scores(:,1),'g')
% % % hold on
% % % plot(scores(:,2),'r')
% % % plot(scores(:,3),'b')
% % % pause(.1)
max_N=min(N1,N2);
X=X(:,1:20);
[best_th1,max_score_1,D0] = opt_th(X(Gender_a==0,:),IHD(Gender_a==0));
[best_th2,max_score_2,D1] = opt_th(X(Gender_a==1,:),IHD(Gender_a==1));
DATA(:,1)=0;
DATA(Gender_a==0,2)=D0(:,2);
DATA(Gender_a==1,2)=D1(:,2);
DATA(Gender_a==0,3)=D0(:,3);
DATA(Gender_a==1,3)=D1(:,3);
function [best_th,max_score1,BEST_DATA]=opt_th(X_,IHD_)
% num_params=size(time_series_names,1);
DATA_=zeros(size(IHD_,1),3);
B = mnrfit(X_,IHD_+1);
PHAT = mnrval(B,X_);
BEST_DATA=[];
max_score1=0;
max_score2=0;
best_th=0;
for class_th=.1:.01:0.5
DATA_(:,1)=str2double('0000');
DATA_(:,2)=PHAT(:,2);
DATA_(:,3)=PHAT(:,2)> class_th;
DATA_(DATA_(:,2)<0.01,2)=0.01;
DATA_(DATA_(:,2)>0.99,2)=0.99;
% if(~isempty(results))
% Calculate sensitivity (Se) and positive predictivity (PPV)
TP=sum(DATA_(IHD_==1,3));
FN=sum(~DATA_(IHD_==1,3));
FP=sum(DATA_(IHD_==0,3));
Se=TP/(TP+FN);
PPV=TP/(TP+FP);
show=0; % if show is 1, the decile graph will be displayed by lemeshow()
% H=lemeshow([IHD_ DATA_(:,2)],show);
% Use the title of figure to display the results
% title(['H= ' num2str(H) ' Se= ' num2str(Se) ' PPV= ' num2str(PPV) '. ' num2str(class_th) ])
% The event 1 score is the smaller of Se and PPV.
score1 = min(Se, PPV);
if score1>max_score1
max_score1=score1;
best_th=class_th;
% max_score2=H;
BEST_DATA=DATA_;
% display(['Unofficial Event 1 score: ' num2str(score1)]);
end
% end
end
% survivals1=sum(X==1 & IHD==0);
% deaths1=sum(X==1 & IHD==1);
% survivals2=sum(X==0 & IHD==0);
% deaths2=sum(X==0 & IHD==1);
%
% disp([' non NaNs:' num2str(deaths1/(deaths1+survivals1)) ])
% disp([' NaNs:' num2str(deaths2/(deaths2+survivals2)) ])
%
max_score1
end
function [best_th,max_score1,BEST_DATA]=opt_th_valid(X_,IHD_)
% num_params=size(time_series_names,1);
n=size(X_,1);
s=zeros(n,1);
s(1:round(n/2))=1;
s=boolean(s);
B = mnrfit(X_(s,:),IHD_(s)+1);
PHAT = mnrval(B,X_(~s,:));
BEST_DATA=[];
DATA_=zeros(size(PHAT,1),3);
max_score1=0;
max_score2=0;
best_th=0;
for class_th=.1:.01:0.5
DATA_(:,1)=str2double('0000');
DATA_(:,2)=PHAT(:,2);
DATA_(:,3)=PHAT(:,2)> class_th;
DATA_(DATA_(:,2)<0.01,2)=0.01;
DATA_(DATA_(:,2)>0.99,2)=0.99;
% if(~isempty(results))
% Calculate sensitivity (Se) and positive predictivity (PPV)
TP=sum(DATA_(IHD_(~s)==1,3));
FN=sum(~DATA_(IHD_(~s)==1,3));
FP=sum(DATA_(IHD_(~s)==0,3));
Se=TP/(TP+FN);
PPV=TP/(TP+FP);
% show=0; % if show is 1, the decile graph will be displayed by lemeshow()
% H=lemeshow([IHD_ DATA_(:,2)],show);
% Use the title of figure to display the results
% title(['H= ' num2str(H) ' Se= ' num2str(Se) ' PPV= ' num2str(PPV) '. ' num2str(class_th) ])
% The event 1 score is the smaller of Se and PPV.
score1 = min(Se, PPV);
if score1>max_score1
max_score1=score1;
best_th=class_th;
% max_score2=H;
BEST_DATA=DATA_;
% display(['Unofficial Event 1 score: ' num2str(score1)]);
end
% end
end
% survivals1=sum(X==1 & IHD==0);
% deaths1=sum(X==1 & IHD==1);
% survivals2=sum(X==0 & IHD==0);
% deaths2=sum(X==0 & IHD==1);
%
% disp([' non NaNs:' num2str(deaths1/(deaths1+survivals1)) ])
% disp([' NaNs:' num2str(deaths2/(deaths2+survivals2)) ])
%
%
% max_score1
end
end