運用matlab實現最基本的離群點診斷,採用歐式距離,並輸出兩點離群因子的比較的視覺化
clc, close all
sdata=
xlsread
('data.xlsx');
of2(7,
10,2,sdata)
function
of2(x,y,k,data)
%比較兩點離群因子
%x,y:需要比較的兩點的id
%k:定義的近鄰點個數
%data:資料總體
dc1=
of1(x,k,data)
;disp([
num2str
(x),
'的離群因子為:'
,num2str
(dc1)])
;dc2=
of1(y,k,data)
;disp([
num2str
(y),
'的離群因子為:'
,num2str
(dc2)])
;if dc1>dc2
disp([
num2str
(x),
'點較'
,num2str
(y),
'點為離群點'])
;elseif dc2>dc1
disp([
num2str
(y),
'點較'
,num2str
(x),
'點為離群點'])
;else
disp
('兩點離群因子相同'
)end
plot1
(x,dc1,y,dc2,data)
endfunction distance =
of1(x,k,data)
%計算離群因子
%x:需計算離群因子點的id
%k:定義的近鄰點個數
%data:資料總體
xc=data
(x,2);
yc=data
(x,3);
new_data=data;
new_data
(x,:)=
;[m,~]
=size
(new_data)
;d_all=
zeros
(m);
for i=1:m
d_1=
sqrt
((xc-
new_data
(i,2))
^2+(yc-
new_data
(i,3))
^2);
d_all
(i)=d_1;
endsort_d_all=
sort
(d_all)
;k_d=0;
for i=1:k
k_d=
sort_d_all
(i)+k_d;
enddistance=k_d/k;
endfunction
plot1
(x,dc1,y,dc2,data)
% 實驗結果的視覺化
xa=data(:
,2);
ya=data(:
,3);
plot
(xa,ya,
'b.'
,'markersize',15
)v=[
0,9,
0,9]
;axis(v
)title
('兩點離群因子比較'
)grid on
xlabel
('x'
)ylabel
('y'
)c1=
[num2str
(x),
' 點的離群因子為 '
,num2str
(dc1)];
char1=
char
(c1)
;c2=
[num2str
(y),
' 點的離群因子為 '
,num2str
(dc2)];
char2=
char
(c2)
;text
(data
(x,2)+
0.3,
data
(x,3)+
0.3,char1)
text
(data
(y,2)+
0.3,
data
(y,3)+
0.3,char2)
hold on
plot
(data
(x,2),
data
(x,3),
'r.'
,'markersize',15
)plot
(data
(y,2),
data
(y,3),
'r.'
,'markersize',15
)if dc1>dc2
c3=([
num2str
(x),
'點較'
,num2str
(y),
'點為離群點'])
;elseif dc2>dc1
c3=([
num2str
(y),
'點較'
,num2str
(x),
'點為離群點'])
;else
c3=('兩點離群因子相同');
endchar3=
char
(c3)
;text(6
,1.5
,char3)
end
如果沒有積分拿的話誰願意寫部落格呢,畢竟我是乙個小菜雞=。= 離群點檢測梳理
描述 離群點檢測,是發現於大部分其他物件顯著不同的物件。大部分分析都會把這些差異資訊丟棄,然而在一些場景中,這些資料可能存在巨大的價值 應用範圍 詐騙檢測 貸款審批 電子商務 網路入侵 天氣預報等領域 分類標準 分類標準 分類描述 資料範圍 全域性離群點和區域性離群點 離群特徵是從區域性和總體來看的...
離群點檢測方法 R語言單元序列離群點檢測
對於一組資料,要找到它的離群值,有很多方法。對於一組資料,要找到它的離群值,有很多方法。這裡在cran上蒐集了一些有趣而易用的離群點檢測包以供後續使用,基本每個r包都有自己的理論和實踐材料做支撐。cran package routliers cran.r project.org cran packa...
python離群點檢測例子 異常點 離群點檢測演算法
異常點 離群點檢測演算法 瀏覽次數 456 sklearn中關於異常檢測的方法主要有兩種 1 novelty detection 當訓練資料中沒有離群點,我們的目標是用訓練好的模型去檢測另外新發現的樣本 2 outlier detection 當訓練資料中包含離群點,模型訓練時要匹配訓練資料的中心樣...