1. 標準化對聚類分析到底有什麼影響?
1) 在講影響之前先羅列一下proc stdize裡面的標準化方法吧
2) 標準化對聚類分析的影響
從圖1中不太容易看清楚標準化對於聚類分析的影響
從圖2可以清晰的看到標準化對於聚類分析的影響
3) 各種標準化方法的比較
一個模擬數據的例子,模擬數據有三個類別,每個類別有100個樣本。我們比較了各種標準化方法之後再進行聚類的誤判情況,可以大概看出各種標準化方法的差異。但此例並不能說明以下方法中誤分類數小的方法就一定優與誤分類數大的方法。有時候還跟數據本身的分佈特徵有關。這個例子也提醒我們有時候我們常用的std和range標準化並不見得是最好的選擇。
附:sas相關代碼
/*********************************************************/
/*1.模擬數據1;測試標準化方法對聚類的影響
模擬數據,樣本量相同,均值和方差不相同*/
/*********************************************************/
data compact;
keep x y c;
n=100;
scale=1; mx=0; my=0; c=1;link generate;
scale=2; mx=8; my=0; c=2;link generate;
scale=3; mx=4; my=8; c=3;link generate;
stop;
generate:
do i=1 to n;
x=rannor(1)*scale+mx;
y=rannor(1)*scale+my;
output;
end;
return;
run;
title '模擬數據1';
proc gplot data=compact;
plot y*x=c;
symbol1 c=blue;
symbol2 c=black;
symbol3 c=red;
run;
proc stdize data=compact method=std
out=scompacted2;
var x y;
run;
title '標準化後的模擬數據1';
proc gplot data=scompacted2;
plot y*x=c;
symbol1 c=blue;
symbol2 c=black;
symbol3 c=red;
run;
/*********************************************************/
/*2.create result table*/
/*********************************************************/
data result;
length method$ 12;
length misclassified 8;
length chisq 8;
stop;
run;
%let inputs=x y;
%let group=c;
%macro standardize(dsn=,nc=,method=);
title \"&method\";
%if %bquote(%upcase(&method))=NONE %then %do;
data temp;
set &dsn;
run;
%end;
%else %do;
proc stdize data=&dsn method=&method out=temp;
var &inputs;
run;
%end;
proc fastclus data=temp maxclusters=&nc least=2
out=clusout noprint;
var &inputs;
run;
proc freq data=clusout;
tables &group*cluster / norow nocol nopercent
chisq out=freqout;
output out=stats chisq;
run;
data temp sum;
set freqout end=eof;
by &group;
retain members mode c;
if first.&group then do;
members=0; mode=0;
end;
members=members+count;
if cluster NE . then do;
if count > mode then do;
mode=count;
c=cluster;
end;
end;
if last.&group then do;
cum+(members-mode);
output temp;
end;
if eof then output sum;
run;
proc print data=temp noobs;
var &group c members mode cum;
run;
data result;
merge sum (keep=cum) stats;
if 0 then modify result;
method = \"&method\";
misclassified = cum;
chisq = _pchi_;
pchisq = p_pchi;
output result;
run;
%mend standardize;
%standardize(dsn=compact,nc=3,method=ABW(.5));
%standardize(dsn=compact,nc=3,method=AGK(.9));
%standardize(dsn=compact,nc=3,method=AHUBER(.5));
%standardize(dsn=compact,nc=3,method=AWAVE(.25));
%standardize(dsn=compact,nc=3,method=EUCLEN);
%standardize(dsn=compact,nc=3,method=IQR);
%standardize(dsn=compact,nc=3,method=L(1));
%standardize(dsn=compact,nc=3,method=L(2));
%standardize(dsn=compact,nc=3,method=MAD);
%standardize(dsn=compact,nc=3,method=MAXABS);
%standardize(dsn=compact,nc=3,method=MEAN);
%standardize(dsn=compact,nc=3,method=MEDIAN);
%standardize(dsn=compact,nc=3,method=MIDRANGE);
%standardize(dsn=compact,nc=3,method=NONE);
%standardize(dsn=compact,nc=3,method=RANGE);
%standardize(dsn=compact,nc=3,method=SPACING(.3));
%standardize(dsn=compact,nc=3,method=STD);
%standardize(dsn=compact,nc=3,method=SUM);
%standardize(dsn=compact,nc=3,method=USTD);
proc sort data=result;
by misclassified;
run;
title '彙總數據';
title2 '聚類判定類別錯誤樣本數排序';
proc print data=result;
run;
閱讀更多 統計學的世界 的文章