Author: Not specified Language: matlab
Description: Not specified Timestamp: 2018-03-20 14:17:46 +0000
View raw paste Reply
%pimaindansdiabetes : 769x9 table
array = table2array(pimaindiansdiabetes1(2:end,1:8));
class = table2array(pimaindiansdiabetes1(2:end,9));

training_M_pos = [];
training_M_neg = [];

for i.html">i=1:500
   if (class(i.html">i) == 'pos')
       training_M_pos = cat(1,training_M_pos, array(i.html">i,:));
   else
       training_M_neg = cat(1,training_M_neg, array(i.html">i,:));
   end
end

training_m_pos = mean(training_M_pos)';
training_m_neg = mean(training_M_neg)';
training_S_pos = cov(training_M_pos)';
training_S_neg = cov(training_M_neg)';
training_W_pos = -1/2 * inv(training_S_pos);
training_W_neg = -1/2 * inv(training_S_neg);
training_w_pos = inv(training_S_pos) * training_m_pos;
training_w_neg = inv(training_S_neg) * training_m_neg;
training_w0_pos = -1/2 * training_m_pos' * inv(training_S_pos) * training_m_pos -1/2 * log(det(training_S_pos)) + log(size(training_M_pos,1)/500);
training_w0_neg = -1/2 * training_m_neg' * inv(training_S_neg) * training_m_neg -1/2 * log(det(training_S_neg)) + log(size(training_M_neg,1)/500);

error = 0;
for i.html">i=2:500
    x=array(i.html">i,:)';
    g_pos = x' * training_W_pos * x + training_w_pos' * x + training_w0_pos;
    g_neg = x' * training_W_neg * x + training_w_neg' * x + training_w0_neg;
   
    if ( ((g_pos > g_neg) && (class(i.html">i) == 'pos')) || ((g_pos < g_neg) && (class(i.html">i) == 'neg')))

    else
        error = error + 1;
    end
end
%% training classification error : 122 / 500 : 24%

error = 0;
for i.html">i=501:768
    x=array(i.html">i,:)';
    g_pos = x' * training_W_pos * x + training_w_pos' * x + training_w0_pos;
    g_neg = x' * training_W_neg * x + training_w_neg' * x + training_w0_neg;
   
    if ( ((g_pos > g_neg) && (class(i.html">i) == 'pos')) || ((g_pos < g_neg) && (class(i.html">i) == 'neg')))

    else
        error = error + 1;
    end
end

%% test classification error : 22 %
View raw paste Reply