% Mean-mean/median-median
% Classification analysis which provides basics of data clasification
clear all
close all
load('input/prepared/Fixacni_stabilita_131030_features');
specificita = [];
senzitivita = [];
presnost = [];
for j=1:16
feature = priznaky{j}.values;
indexes = priznaky{j}.indexes;
dys=feature(indexes{1});
con=feature(indexes{2});
prah=min([mean(dys) mean(con)])+abs(mean(dys)-mean(con))/2

        if mean(dys)>mean(con) 
        dys_k=dys>prah;
        con_k=con<prah;
        else
        dys_k=dys<prah;
        con_k=con>prah;
        end;

tp=sum(dys_k)+sum(con_k)
fp=sum(~dys_k)+sum(~con_k)
score=tp/(tp+fp)*100

TP = 0;
FP = 0;
TN = 0;
FN = 0;
class = priznaky{j}.class;

%    True positive: Sick people correctly diagnosed as sick
TP=sum(dys_k)
%    False positive: Healthy people incorrectly identified as sick
FP=sum(~con_k)
%    True negative: Healthy people correctly identified as healthy
TN=sum(con_k)
%    False negative: Sick people incorrectly identified as healthy
FN=sum(~dys_k)

senzitivita(j) = TP/(TP+FN)
specificita(j) = TN/(TN+FP)
presnost(j)= (TP + TN)/(TN+TP+FN+FP)

%% Control
assert(presnost(j)*100==score)

spravne_oznaceni_dys_procent=sum(dys_k)/length(dys_k)*100
spravne_oznaceni_con_procent=sum(con_k)/length(con_k)*100
spatne_oznaceni_dys_procent=sum(~dys_k)/length(dys_k)*100
spatne_oznaceni_con_procent=sum(~con_k)/length(con_k)*100

end
Tmean = table(presnost',senzitivita',specificita')

writetable(Tmean,'Tmean.csv')