全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
19634 36
2014-05-09
SAS中的聚类分析方法总结(1)——聚类分析概述

SAS中的聚类分析方法总结(1)——聚类分析概述(续1)


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


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


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


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


      2.png


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

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

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

附:本节相关sas代码就作为回帖吧。

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2014-5-9 16:15:42
/*********************************************************/
/*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;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-5-12 09:58:01
very good
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-5-13 01:39:13
赞 分享~~~
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-5-20 01:19:57
赞 分享~~~
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-5-21 16:51:23
谢楼主啊!
非常感谢,学习了!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群