Author: Not specified Language: matlab
Description: Not specified Timestamp: 2018-03-21 03:29:18 +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 = cov(array(2:500))';

training_w_pos = inv(training_S) * training_m_pos;
training_w_neg = inv(training_S) * training_m_neg;

training_w0_pos = -1/2 * training_m_pos' * inv(training_S) * training_m_pos + log(size(training_M_pos,1)/500);
training_w0_neg = -1/2 * training_m_neg' * inv(training_S) * training_m_neg + log(size(training_M_neg,1)/500);

error = 0;
for i.html">i=2:500
    x=array(i.html">i,:)';
    g_pos = training_w_pos' * x + training_w0_pos;
    g_neg = 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 : 180 / 500 : 36%

error = 0;
for i.html">i=501:768
    x=array(i.html">i,:)';
    g_pos = training_w_pos' * x + training_w0_pos;
    g_neg = 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 : 39 %

%% linear discriminent
 
View raw paste Reply