SAS中文论坛

 找回密码
 立即注册

扫一扫,访问微社区

查看: 1039|回复: 0
打印 上一主题 下一主题

SAS EM:Association node(关联节点)

[复制链接]

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
楼主
 楼主| 发表于 2010-10-22 22:51:31 | 只看该作者

SAS EM:Association node(关联节点)

From supersasmacro's blog on Sina

<div>SAS EM:Association node(关联节点)</DIV>
<div><br /></DIV>
<div>SAS EM(Enterprise Miner)企业数据挖掘节点功能详解及代码实现(第五弹)</DIV>
<div><br /></DIV>
<div>本文未经作者允许,请勿转载</DIV>
<div><br /></DIV>
<div>
在一个事件或是一笔记录中,不同项目一起发生的机率,借着发掘关联规则,形成每一个关联和顺序,让用户确认数据间关联关系。如:尿布和啤酒的关系。</DIV>
<div>
这些关联规则发掘的基础是建立在项目单独和一起在数据库中发生的频率次数,一个关联规则可能表达成“如果项目A是事件的一部分,则项目B也是事件的一部分,这样的情形发生的机率有X“。这些关联规则不能解释成直接的因果关系,但是可以解释成两个或是多的项目的关联,然而发掘这些可信的关联规可供企业决策,例如:商品的促销或是摆设。</DIV>
<div>在这边可以设定关联规则的参数有:&nbsp;</DIV>
<div> Minimum Transaction
Frequency:最小的支持度(Support),也就是项目在整个数据库中一起发生的机率。</DIV>
<div> Maximum Number of Items in an Association:最大在关联集合的项目数。</DIV>
<div> Minimum Confidence:最小的置信度(Confidence),也就是项目一起发生的正确率。</DIV>
<div>例如SAS Help里面的例子:</DIV>
<div>&nbsp;<a href="http://blog.photo.sina.com.cn/showpic.html#url=http://static11.photo.sina.com.cn/orignal/5d3b177cg8c33da971a9a" TARGET="_blank"><img SRC="http://static11.photo.sina.com.cn/middle/5d3b177cg8c33da971a9a&amp;690" WIDTH="419" HEIGHT="249" /></A></DIV>
<br />
<div>也即是:如果一个客户买了鞋的话,那么他有10%的可能性会买袜子,这样的客户占总客户数的2%。</DIV>
<div><br /></DIV>
<div>进阶的参数有:</DIV>
<div> Calculate Maximum Number of Associations Using
2**n:这个选项可决定最大的关联数。</DIV>
<div> Customize
Sort:自定义化的排序,如果关联规则小于或等于100,000个,则它会依照支持来排序,如果大于100,000个,就不会作排序的动作。</DIV>
<div><br /></DIV>
<div>SAS
EM的关联规则用的是Apriori算法,其核心思想是把发现关联规则的工作分为两步:第一步通过迭代检索出事务数据库中的所有频繁项集,即频繁项集的支持度不低于用户设定的阈值;第二步从频繁项集中构造出满足用户最低信任度的规则。</DIV>
<div><br /></DIV>
<div>Association node(关联节点)</DIV>
<div>1 Association:</DIV>
<div><a href="http://blog.photo.sina.com.cn/showpic.html#url=http://static11.photo.sina.com.cn/orignal/5d3b177cg8c33dec26f2a" TARGET="_blank"><img SRC="http://static11.photo.sina.com.cn/middle/5d3b177cg8c33dec26f2a&amp;690" WIDTH="500" HEIGHT="300" NAME="image_operate_6171280054478033" /></A></DIV>
<div><a href="http://blog.photo.sina.com.cn/showpic.html#url=http://static11.photo.sina.com.cn/orignal/5d3b177cg8c33dec26f2a" TARGET="_blank"></A><a href="http://blog.photo.sina.com.cn/showpic.html#url=http://static2.photo.sina.com.cn/orignal/5d3b177cg8c33dea3d411" TARGET="_blank"><img SRC="http://static2.photo.sina.com.cn/middle/5d3b177cg8c33dea3d411&amp;690" WIDTH="690" HEIGHT="77" STYLE="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial;" NAME="image_operate_35571280054478516" /></A><br STYLE="font-family: 宋体, Verdana, Arial, Helvetica, sans-serif; line-height: 1.5;" />

<a href="http://blog.photo.sina.com.cn/showpic.html#url=http://static9.photo.sina.com.cn/orignal/5d3b177cg746b971b1d98" TARGET="_blank"><img SRC="http://static9.photo.sina.com.cn/middle/5d3b177cg746b971b1d98&amp;690" WIDTH="631" HEIGHT="256" NAME="image_operate_64111280054479588" /></A><br />
&nbsp;</DIV>
<div>对上面图片进行一些说明:</DIV>
<div>这里,关联分析有三种分析模式:</DIV>
<div>by context:根据输入数据集自动判断用哪一种分析模式</DIV>
<div>Association:关联</DIV>
<div>Sequences:序列</DIV>
<div>Minimum Transaction Frequency:设置最小的支持度(Support),用来减少规则数量</DIV>
<div>Maximum Number of Items in an
Association:最大在关联集合的项目数,这里最多4项。</DIV>
<div>Minimum
Confidence:最小的置信度(Confidence),也就是项目一起发生的正确率,这里至少10%的置信度。</DIV>
<div><br /></DIV>
<div>代码:</DIV>
<div>data EMDATA.VIEW_ZMK / view=EMDATA.VIEW_ZMK;</DIV>
<div>&nbsp;set EMSAMPLE.BNKSERV;</DIV>
<div>run;</DIV>
<div><br /></DIV>
<div>*创建数据挖掘数据集;</DIV>
<div>proc dmdb data =EMDATA.VIEW_ZMK&nbsp;</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;out
=_null_&nbsp;</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp;
&nbsp;dmdbcat=EMPROJ.dm_DGM00000</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;normlen=256
maxlevel=100001;</DIV>
<div>&nbsp;&nbsp; &nbsp; id
ACCT;</DIV>
<div>&nbsp;&nbsp; &nbsp; class
SERVICE(Desc);</DIV>
<div>&nbsp;&nbsp; &nbsp; target
SERVICE;</DIV>
<div>run;</DIV>
<div><br /></DIV>
<div>* 创建视图;</DIV>
<div>data EMDATA.dm_DGM00000 / view=EMDATA.dm_DGM00000;</DIV>
<div>&nbsp;set EMDATA.VIEW_ZMK;</DIV>
<div>run;</DIV>
<div><br /></DIV>
<div>proc sort data=EMDATA.VIEW_ZMK( keep=SERVICE ACCT)</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp;
&nbsp;out=_emtrain ;</DIV>
<div>&nbsp;&nbsp; &nbsp; by
ACCT;</DIV>
<div>run;</DIV>
<div><br /></DIV>
<div>* 关联规则;</DIV>
<div>
*SAS的关联规则使用的是Aprior算法,该算法将发现关联规则的过程分为两个步骤:第一步通过迭代,检索出事务数据库中的所有频繁项集,即支持度不低于用户设定的阈值的项集;第二步利用频繁项集构造出满足用户最小信任度的规则。其中,挖掘或识别出所有频繁项集是该算法的核心,占整个计算量的大部分。;</DIV>
<div>*这里实现第一步:检索出事务数据库中的所有频繁项集。也即是计算出各种组合的频率;</DIV>
<div>options nocleanup;</DIV>
<div>Proc Assoc dmdbcat= EMPROJ.dm_DGM00000</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; data =
_emtrain</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; out =
EMDATA.ASCRGEY1 (label = "Output from Proc Assoc")</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; items=4;
&nbsp; &nbsp; *最小items;</DIV>
<div>&nbsp;&nbsp; &nbsp;
customer ACCT;</DIV>
<div>&nbsp;&nbsp; &nbsp; target
SERVICE;</DIV>
<div>run;</DIV>
<div>*结果;</DIV>
<div>&nbsp;<a href="http://blog.photo.sina.com.cn/showpic.html#url=http://static10.photo.sina.com.cn/orignal/5d3b177cg8c33ec77c779" TARGET="_blank"><img SRC="http://static10.photo.sina.com.cn/middle/5d3b177cg8c33ec77c779&amp;690" WIDTH="431" HEIGHT="623" /></A></DIV>
<br />
<div><br /></DIV>
<div>**生成规则;</DIV>
<div>**然后第二步:第二步利用频率项集构造出满足用户最小置信度的规则;</DIV>
<div>options nocleanup;</DIV>
<div>Proc Rulegen in = EMDATA.ASCRGEY1</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;
&nbsp; out= EMDATA.RLAAT6S4 (label = "Output from Proc
Rulegen")</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;
&nbsp; minconf = 10; &nbsp;
*最小confidence;</DIV>
<div>run;</DIV>
<div>quit;</DIV>
<div>*结果;</DIV>
<div>&nbsp;<a href="http://blog.photo.sina.com.cn/showpic.html#url=http://static11.photo.sina.com.cn/orignal/5d3b177cg8c33ee8a829a" TARGET="_blank"><img SRC="http://static11.photo.sina.com.cn/middle/5d3b177cg8c33ee8a829a&amp;690" WIDTH="690" HEIGHT="421" NAME="image_operate_23331280054588578" /></A></DIV>
<br />
<div>注意,这里有left hand of rule以及right hand of
rule。两者是不一样的,这里要说明一下,</DIV>
<div>Confidence(A→B):B出现在包含A的事务中的概率,即N(AB)/N(A)。</DIV>
<div>Confidence(B→A):A出现在包含B的事务中的概率,即N(AB)/N(B)。</DIV>
<div><br /></DIV>
<div>proc dmdb data = EMDATA.RLAAT6S4&nbsp;</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;dmdbcat=
EMPROJ.TMP_XDRE&nbsp;</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp;
&nbsp;batch;</DIV>
<div>&nbsp;&nbsp; &nbsp; var
set_size support conf lift count;</DIV>
<div>run;</DIV>
<div>quit;</DIV>
<div><br /></DIV>
<div><br /></DIV>
<div>2 sequence 序列关联</DIV>
<div>&nbsp;<a href="http://blog.photo.sina.com.cn/showpic.html#url=http://static13.photo.sina.com.cn/orignal/5d3b177cg8c33efed35fc" TARGET="_blank"><img SRC="http://static13.photo.sina.com.cn/middle/5d3b177cg8c33efed35fc&amp;690" WIDTH="500" HEIGHT="300" /></A></DIV>
<br />
<a href="http://blog.photo.sina.com.cn/showpic.html#url=http://static15.photo.sina.com.cn/orignal/5d3b177cg8c33f2a7d9fe" TARGET="_blank"><img SRC="http://static15.photo.sina.com.cn/middle/5d3b177cg8c33f2a7d9fe&amp;690" WIDTH="690" HEIGHT="81" /></A><br />
<br />
<div>&nbsp;</DIV>
<div><br /></DIV>
<div>代码:</DIV>
<div>data EMDATA.VIEW_ZMK / view=EMDATA.VIEW_ZMK;</DIV>
<div>&nbsp;set EMSAMPLE.ASSOCS;</DIV>
<div>run;</DIV>
<div><br /></DIV>
<div>*创建数据挖掘数据集;</DIV>
<div>proc dmdb data = EMDATA.VIEW_ZMK&nbsp;</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;out =
_null_&nbsp;</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;dmdbcat=
EMPROJ.dm_DGM00000</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;normlen=256
maxlevel=100001;</DIV>
<div>&nbsp;&nbsp; &nbsp; id
CUSTOMER;</DIV>
<div>&nbsp;&nbsp; &nbsp; class
PRODUCT(Desc);</DIV>
<div>&nbsp;&nbsp; &nbsp; target
PRODUCT;</DIV>
<div>run;</DIV>
<div><br /></DIV>
<div>* Create data view with dmdb name;</DIV>
<div>data EMDATA.dm_DGM00000 / view=EMDATA.dm_DGM00000;</DIV>
<div>&nbsp;set EMDATA.VIEW_ZMK;</DIV>
<div>run;</DIV>
<div><br /></DIV>
<div>proc sort data =EMDATA.VIEW_ZMK( keep=PRODUCT CUSTOMER
TIME)&nbsp;</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;out
=_emtrain ;&nbsp;</DIV>
<div>&nbsp;&nbsp; &nbsp; by
CUSTOMER TIME;&nbsp;</DIV>
<div>run;&nbsp;</DIV>
<div>这里因为我们已经指定了sequence变量,因此,analysis mode为by
context时,自动定位到sequences。我们就可以设置sequences选项</DIV>
<div>&nbsp;<a href="http://blog.photo.sina.com.cn/showpic.html#url=http://static13.photo.sina.com.cn/orignal/5d3b177cg8c33f47b9dac" TARGET="_blank"><img SRC="http://static13.photo.sina.com.cn/middle/5d3b177cg8c33f47b9dac&amp;690" WIDTH="637" HEIGHT="207" /></A></DIV>
<br />
<div><br /></DIV>
<div>*关联算法;</DIV>
<div>options nocleanup;&nbsp;</DIV>
<div>Proc Assoc dmdbcat= EMPROJ.dm_DGM00000&nbsp;</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; data
&nbsp; = _emtrain&nbsp;</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; out
&nbsp; &nbsp;= EMDATA.ASCV12SK (label =
"Output from Proc Assoc")&nbsp;</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; items
&nbsp;= 4;&nbsp;</DIV>
<div>&nbsp;&nbsp; &nbsp;
customer CUSTOMER;&nbsp;</DIV>
<div>&nbsp;&nbsp; &nbsp; target
PRODUCT;&nbsp;</DIV>
<div>run;&nbsp;</DIV>
<div>quit;</DIV>
<div>这里的设置与association类似,即设置最小支持度,以及最大关联项目数:</DIV>
<div>&nbsp;<a href="http://blog.photo.sina.com.cn/showpic.html#url=http://static10.photo.sina.com.cn/orignal/5d3b177cg8c33f98d22f9" TARGET="_blank"><img SRC="http://static10.photo.sina.com.cn/middle/5d3b177cg8c33f98d22f9&amp;690" WIDTH="638" HEIGHT="208" /></A></DIV>
<br />
<div>还可以设置一些时间序列特有的选项:时间约束:</DIV>
<div>&nbsp;<a href="http://blog.photo.sina.com.cn/showpic.html#url=http://static5.photo.sina.com.cn/orignal/5d3b177cg8c33f6d8cc84" TARGET="_blank"><img SRC="http://static5.photo.sina.com.cn/middle/5d3b177cg8c33f6d8cc84&amp;690" WIDTH="638" HEIGHT="211" STYLE="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial;" NAME="image_operate_76641280054727356" /></A></DIV>
<div><br /></DIV>
<div>**得到序列分析结果;</DIV>
<div>options nocleanup;&nbsp;</DIV>
<div>Proc sequence data &nbsp; =
_emtrain&nbsp;</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;dmdbcat=
EMPROJ.dm_DGM00000&nbsp;</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;assoc &nbsp;=
EMDATA.ASCV12SK&nbsp;</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;out &nbsp;
&nbsp;= EMDATA.RLS0JZQR (label = "Output from Proc
Sequence")</DIV>
<div>&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;nitems =
3;&nbsp;</DIV>
<div>&nbsp;&nbsp; &nbsp;
customer CUSTOMER;&nbsp;</DIV>
<div>&nbsp;&nbsp; &nbsp; target
&nbsp; PRODUCT;&nbsp;</DIV>
<div>&nbsp;&nbsp; &nbsp; visit
&nbsp; &nbsp;TIME;&nbsp;</DIV>
<div>run;</DIV>
<div>quit;</DIV>
<div>最终结果:</DIV>
<div>&nbsp;<a href="http://blog.photo.sina.com.cn/showpic.html#url=http://static2.photo.sina.com.cn/orignal/5d3b177cg746b99d0dc81" TARGET="_blank"><img SRC="http://static2.photo.sina.com.cn/middle/5d3b177cg746b99d0dc81&amp;690" /></A></DIV>
<br />
<div>这里对结果说明一下:</DIV>
<div>序列关联最后的表现形式为:如果A发生的话,那么过一段时间后,B也将发生。</DIV>
<div><br /></DIV>
<div><br /></DIV>
<div><br /></DIV>
<div>本文用到的SAS数据集为assocs.sas7bdat,其下载地址:</DIV>
<div><!-- m --><a class="postlink" href="http://ishare.iask.sina.com.cn/f/8641119.html">http://ishare.iask.sina.com.cn/f/8641119.html</a><!-- m --></DIV>
<div>本文用到的SAS数据集为bnkserv.sas7bdat,其下载地址:</DIV>
<div><!-- m --><a class="postlink" href="http://ishare.iask.sina.com.cn/f/8641120.html">http://ishare.iask.sina.com.cn/f/8641120.html</a><!-- m --></DIV>
<div>本系列全部数据下载地址:</DIV>
<div><!-- m --><a class="postlink" href="http://iask.sina.com.cn/u/1564153724/ish">http://iask.sina.com.cn/u/1564153724/ish</a><!-- m --></DIV>
<div><br /></DIV><div style="border-top: 1px solid rgb(203, 217, 217); padding-top: 20px; padding-bottom: 10px;">
<p><br><a href="http://move.blog.sina.com.cn/admin/blogmove/blogmove_msn.php" target="_blank">MSN空间完美搬家到新浪博客!</a></p></div>
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SAS中文论坛  

GMT+8, 2026-2-3 18:28 , Processed in 0.065746 second(s), 19 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表