資源簡介
LOF算法:剔除異常值,用于數(shù)據(jù)量不大,使用簡單,并具有可視化功能,可將異常數(shù)據(jù)在圖上顯示出來

代碼片段和文件信息
%LOF算法
function?lof?=??LOF(dist)
K=10;
m=size(dist1);?????????????????%m為對象數(shù),dist為兩兩之間的距離
distance?=?zeros(mm);
num?=?zeros(mm);???????????????%distance?和num用來記錄排序后的順序,和對象編號順序
kdistance?=??zeros(m1);?????????%計算每個對象的kdistance
count??=?zeros(m1);????????????%k鄰域的對象數(shù)
reachdist?=??zeros(mm);?????????%計算兩兩之間的reachable-distance
lrd?=?zeros(m1);
lof?=?zeros(m1);
%計算k-距離
for?i=1:m
?????[distance(i:)num(i:)]=sort(dist(i:)‘a(chǎn)scend‘);
????kdistance(i)=distance(iK+1);
????count(i)?=?-1;%自己的距離為0,要去掉自己
????for?j?=?1:m
????????if?dist(ij)<=kdistance(i)
????????????count(i)?=?count(i)+1;
????????end
????end
end??
for?i?=?1:m
????for?j=1:i-1
????????reachdist(ij)?=??max(dist(ij)kdistance(j));
????????reachdist(ji)?=?reachdist(ij);
????end
end
for?i?=?1:m
????sum_reachdist=0;
????for?j=1:count(i)
?????????sum_reachdist=sum_reachdist+reachdist(inum(j+1));
????end
????%計算每個點的lrd
????lrd(i)=count(i)/sum_reachdist;
end
%?得到lof值
for?i=1:m
????sumlrd=0;
????for?j=1:count(i)
????????sumlrd=sumlrd+lrd(num(j+1))/lrd(i);
????end
????lof(i)=sumlrd/count(i);
end
end
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??1980-01-01?00:00??CSDN\lof\
?????文件????????1198??2019-05-04?18:21??CSDN\lof\LOF.m
?????文件????????1172??2019-05-04?18:21??CSDN\lof\lof(1).zip
?????文件?????2458662??2019-05-04?18:21??CSDN\lof\剔除測量數(shù)據(jù)中異常值的若干方法_何平.pdf
評論
共有 條評論