聚类分析总结(3)——标准化对聚类的影响

1. 标准化对聚类分析到底有什么影响?

1) 在讲影响之前先罗列一下proc stdize里面的标准化方法吧

\"聚类分析总结(3)——标准化对聚类的影响\"

2) 标准化对聚类分析的影响

从图1中不太容易看清楚标准化对于聚类分析的影响

\"聚类分析总结(3)——标准化对聚类的影响\"

从图2可以清晰的看到标准化对于聚类分析的影响

\"聚类分析总结(3)——标准化对聚类的影响\"

3) 各种标准化方法的比较

一个模拟数据的例子,模拟数据有三个类别,每个类别有100个样本。我们比较了各种标准化方法之后再进行聚类的误判情况,可以大概看出各种标准化方法的差异。但此例并不能说明以下方法中误分类数小的方法就一定优与误分类数大的方法。有时候还跟数据本身的分布特征有关。这个例子也提醒我们有时候我们常用的std和range标准化并不见得是最好的选择。

\"聚类分析总结(3)——标准化对聚类的影响\"

附: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;


分享到:


相關文章: