Predicting Mortality of ICU Patients: The PhysioNet/Computing in Cardiology Challenge 2012 1.0.0
(1,367 bytes)
function [accuracy,labelsEstim,probs,probsAll] = predict_LRoma(w,X,y)
% logreg prediction results
%
% Inputs:
%
% w - esimated model parameters (see "objFuncLR.m" for details)
% X - data matrix (see "objFuncLR.m" for details)
% y - category labels. NOTE! These must be given in conventional
% format as a vector of numeric values {1,2,...,M}, where M is
% the number of categories. "objFuncLR.m" requires binary format.
%
% accuracy - prediction accuracy
% labelsEstim - estimated category labels
% probs - probability estimates of the predictions
% probsAll - probability estimates of all categories
%
% Jukka-Pekka Kauppi
% jukka-pekka.kauppi@helsinki.fi
% University of Helsinki, Department of Computer Science
% Last modified: 23.8.2012
n = size(X,1);
d = size(X,2);
M = max(y);
X = [X ones(size(X,1),1)];
if M > 2
w = reshape(w,(d+1),M);
q_tm = zeros(n,M); %n*M
for m = 1:M
q_tm(:,m) = X*w(:,m);
end
R = sum(exp(q_tm),2); % n*1;
Ptm = (exp(q_tm)./repmat(R,1,M))'; % M*n
[probs labelsEstim] = max(Ptm);
probsAll = Ptm;
else
q_t = X*w;
exp_q_t = exp(q_t);
R = 1 + exp_q_t;
P_t = exp_q_t ./ R;
probsAll = [P_t' ;1-P_t'];
[probs labelsEstim] = max(probsAll);
end
labelsEstim = labelsEstim(:)';
probs = probs(:)';
% compute total classification accuracy:
y = y(:)';
accuracy = sum(labelsEstim == y)/length(y);