Predicting Mortality of ICU Patients: The PhysioNet/Computing in Cardiology Challenge 2012 1.0.0

File: <base>/sources/alistairewj_at_gmail.com/entry6/physionet2012.m (3,335 bytes)
function [prob,died]=physionet2012(tm,category,val)
% [prob,died]=physionet2012(tm,category,val) 
%   Submission for the PhysioNet 2012 Challenge. This function takes about
%   120 seconds per patient. Requires the statistics toolbox. 
%   Should run with genresults.m framework. Runs with genresults_D.m
%   framework in ~1200 seconds, this is much faster, but evaluates on all
%   patients at once. Apologies as the code has not yet been optimized for
%   individual by individual prediction.
%
%   Outputs already generated in Outputs-b.txt
%
%	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-05-29 09:01:11 -0400 (Tue, 29 May 2012) $
%	$Revision: 1 $
%	Originally written on GLNXA64 by Alistair Johnson, 24-Apr-2012 14:02:25
%	Contact: alistairewj@gmail.com

%=== Miscellanious default values
T=0.336231437010673; % Mortality threshold that maximizes SE/PPV

%=======================%
%=== PREPROCESS DATA ===%
%=======================%
%=== Put into expected format for function
if nargin<3
    if iscell(tm) && size(tm,2)>=3
        data = tm; % assume multi-observation input
    else
        error('Incorrect input.');
    end
elseif nargin==3
    % 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}];
end
data = pnPreprocess(data,0);

%=====================%
%=== LOAD FEATURES ===%
%=====================%
[X,header] = pnBaseFeatures(data);

%==================%
%=== LOAD MODEL ===%
%==================%
model = load('pnSubmission1_140812.mat');

%===============================%
%=== MODEL FEATURE SELECTION ===%
%===============================%
% if isfield(model,'idxRem')
% %=== Parse data for problematic features
% [X,header] = pnParseData(X,header,idxRem);
% end


%===============================%
%=== MODEL PARSING ===%
%===============================%
if any(strcmp(header,model.header)==0)
    fprintf('Header mismatch!\n');
end
model = model.model;
model.xtrain = sort(model.xtrain,1,'ascend');
if isfield(model,'T')
    T = model.T;
end
% if isfield(model,'xtrain')
%     %=== model probably in the right form
% elseif isfield(model,'model')
%     if iscell(model.model)
%         model = model.model{1};
%     elseif isstruct(model.model)
%         model = model.model;
%     end
%     if isfield(model,'xtrain')
%         %=== we are happy
%     else
%         fprintf('MAT file seems to be in the wrong format...\n');
%     end
% end

%===================%
%=== CLASSIFY ======%
%===================%
[ prob ] = NicForest_apply_quick(model, X);
% [ prob ] = NicForest_apply(model,X);
%===================%
%=== SET OUTPUTS ===%
%===================%
died = prob >= T; % Thresholded probability to maximize PPV/Sens

end