Demo entry 6657156

PLA Pocket Algorithm

   

Submitted by anonymous on Nov 02, 2017 at 15:30
Language: Matlab. Code size: 1.4 kB.

clear A
clear P
clear R
clear TPRsave
clear FPRsave
clear F1Meansure

% augmented matrix
xn=augmentedmatrix(train);
% initial w
% initial Accuracy
size_label=size(label);
sizeL=size_label(1);
size_xn=size(xn);

% predictlabel=-(ones(size(label)));
Rand=randi([0,1],size_label(1),size_label(2));
Rand(Rand==0)=-1;
predictlabel=Rand;
Acc=Accuracy(label,predictlabel,sizeL);

tim=1;
count=1;

A=[];
P=[];
R=[];
TPRsave=[];
FPRsave=[];
F1Meansure=[];

maxAcc=0;
maxF1=0;
maxW=ones(size_xn(1),1);
new_w=ones(size_xn(1),1);

w=10000*rand(size_xn(1),1);
while(tim<=1000)
    
    for iterator=1:size_xn(2)
        predictlabel(iterator)=Sign((w')*xn(:,iterator));
        if predictlabel(iterator)~=label(iterator)
            new_w=w+label(iterator)*xn(:,iterator);
            w=new_w;
        end
    end

    Acc=Accuracy(label,predictlabel,sizeL);
    Pre=Precision(label,predictlabel,sizeL);
    Rec=Recall(label,predictlabel,sizeL);
    TPR=TruePositiveRate(label,predictlabel,sizeL);
    FPR=FalsePositiveRate(label,predictlabel,sizeL);
    F=F1(Pre,Rec,5);
    A=[A,Acc];
    P=[P,Pre];
    R=[R,Rec];
    TPRsave=[TPRsave,TPR];
    FPRsave=[FPRsave,FPR];
    F1Meansure=[F1Meansure,F];
    
    if F>maxF1
            maxF1=F;
            maxW=new_w;
    end
    tim=tim+1;
end
    

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).