IRONYUNS / AADS

Autonomous Anomaly Detection for Streaming Data
1 stars 0 forks source link

Functions Regarding Performance Metrics #1

Closed dxc24 closed 1 hour ago

dxc24 commented 4 days ago

"Excuse me, could you please share the code regarding performance metrics? I would greatly appreciate it."

IRONYUNS commented 3 days ago

Hello dxc24

The true positive code is as follows.


%clear everything before begins
clc;
clear all

%read original data
data = load('ionosphere.mat');

%assign X(data) and y(anomaly label) 
data2 = data.X;
data3 = data.y;

%get the number of row from y
sz1 = size(data2,1);

%read result data
data = load('matlab.mat'); 

%read clust member
data = data.clustMember;

%get the number of row from clust member
sz = size(data,1);

%anomaly calculator (true positive if < support [line 30])
calc = 0;

%get into each clust member
for i=1:sz
    %read i-th clust member and check the condition {[ 8 here is support}]
    if size(data{i,1},1) < 8
        %get into m-th member in i-th clust member
        for m=1:size(data{i,1},1)
            %get into original number of data
            for j=1:sz1
                %check result data whether it is the same as original
                %(check row with row)
                if isequal(data{i,1}(m,:),data2(j,:))
                    %if result is anomaly (False Positive will be 0)
                    if data3(j,1) == 1
                        calc = calc + 1;
                    end
                end
            end
        end
    end
end

You can also use it to identify false positives.

While this code might not be perfect, it does contain the logic to find true positives.

You can apply the same logic to develop your own performance metrics code if the current one doesn't meet your needs.

Feel free to share your code if you'd like.

I hope this helps.

Thank you.

IRONYUNS commented 1 hour ago

Feel free to reopen the issue if there are any problems or if you would like to share the performance metrics code.