Predicting Mortality of ICU Patients: The PhysioNet/Computing in Cardiology Challenge 2012 1.0.0
(2,457 bytes)
function [prob,died]=physionet2012_F(tm,category,val)
% [prob,died]=physionet2012(tm,category,val)
% Submission A for the PhysioNet 2012 Challenge.
%
% Inputs:
% tm - (Nx1 Cell Array) Cell array containing time of measurement
% category- (Nx1 Cell Array) Cell array containing type (category)
% measurement
% value - (Nx1 Cell Array) Cell array containing value of measurement
%
% Outputs:
% prob - (Scalar) Probability value of the patient dying in the hospital
% died - (Logical) Binary classification if the patient is going to die
% on the hospital (1 - Died, 0 - Survived)
%
% Example
% [prob,died]=physionet2012(tm,category,val)
% Copyright 2012 Alistair Johnson
% $LastChangedBy: alistair $
% $LastChangedDate: 2012-04-25 01:27:43 +0100 (Wed, 25 Apr 2012) $
% $Revision: 345 $
% Originally written on GLNXA64 by Alistair Johnson, 24-Apr-2012 14:02:25
% Contact: alistairewj@gmail.com
%=== Miscellanious default values
%=======================%
%=== PREPROCESS DATA ===%
%=======================%
%=== Put into expected format for function
% Convert time from string to numeric minutes
tm = cellfun(@(x) str2double(x(1:2)), tm)*60 + cellfun(@(x) str2double(x(4:5)),tm);
data = [{1},{tm},{category},{val}];
[ data ] = pnPreprocess(data);
%=====================%
%=== LOAD FEATURES ===%
%=====================%
load datahi;
[ X ] = pniExtractFeaturesF(data);
idxTraining = true(4000,1);
idxTraining(4:4:end) = false;
idxTest = ~idxTraining;
medianVals = median(X(idxTraining,:),1);
for k=1:size(X,2)
medianVals(k)
lr = glmfit(X(idxTraining,:),data_target(idxTraining),'binomial');
[pred] = glmval(lr,X,'logit');
prob = pred;
stats = stat_calc_struct(prob(idxTest),data_target(idxTest));
temp=prob;
temp=sort(temp,'descend');
TP=cumsum(temp);
FP=cumsum(1-temp);
FN=cumsum(temp(length(temp):-1:1));
FN=FN(length(FN):-1:1);
temp2=zeros(length(temp),1);
t1=TP./(TP+FN);
t2=TP./(TP+FP);
for(i=1:length(temp))
temp2(i)=min(t1(i),t2(i));
end
[t1 t2]=max(temp2);
T = temp(t2);
%===================%
%=== CLASSIFY ======%
%===================%
%=== Load trained rf
mdl=load('ModelF.mat');
[~,pred] = predict(mdl.rf,X);
prob = pred(:,2);
prob = glmval(mdl.betas,prob,'logit');
%===================%
%=== SET OUTPUTS ===%
%===================%
died = prob >= mdl.T; % Thresholded probability to maximize PPV/Sens
end